DB2 reading notes

zhaozj2021-02-16  42

View table space

1.Get Snapshot for TableSpaces on

2.List Tablespaces (Show Details) (SHOW DETAILS)

note:

The container can only be built in this site and cannot be created in a network mapping disk, an NFS file system, or a GPFS file system.

View index

Select * from syscat.indexes where tabname = Upper ('table name)

DB2 common command

1. Start database

DB2Start

2. Stop database

DB2STOP FORCE

3. Connect to the database

DB2 Connect To O_YD User DB2 Using PWD

4. Read the database management program configuration

DB2 GET DBM CFG

5. Write database management program configuration

DB2 UPDATE DBM CFG Using Parameter Name Parameter Value

6. Read the configuration of the database

DB2 Connect To O_YD User DB2 Using PWD

DB2 Get DB CFG for o_YD

7. Write the configuration of the database

DB2 Connect To O_YD User DB2 Using PWD

DB2 UPDATE DB CFG for o_YD Using Parameter Name Parameter Value

8. Turn off all applications

DB2 "Force Application All"

DB2 "Force Application (ID1, ID2,, IDN)"

(DB2 List Application for DB O_YD Show Detail)

9. backup database

DB2 Force Application All

DB2 Backup DB o_yd to d:

(DB2 Initialize Tape on //./tape0)

(DB2 Rewind Tape on //./tape0)

DB2 Backup DB o_yd to //./tape0

10. Restore database

DB2 Restore DB O_YD from D: To D:

DB2 Restore DB o_yd from //./tape0 to d:

11. Binding stored procedure

DB2 Connect To O_YD User DB2 Using PWD

DB2 BIND C: /DFPLUS.BND

Copy the stored procedure to the C: / Sqllib / Function directory on the server

12. Finishing table

DB2 Connect To O_YD User DB2 Using PWD

DB2 REORG TABLE YDD

DB2 Runstats on Table YDD with Distribution and Indexes All

13. Export table data

DB2 Export To C: /DFTZ.TXT OF DEL SELECT * FROM DFTZ

DB2 Export to C: /DFTZ.IXF of IXF SELECT * FROM DFTZ

14. Import table data

Import from c: /123.txt of del insert Into YLBX.CZYXX

DB2 Import to C: /DFTZ.TXT OF DEL Commitcount 5000 Messages C: /DFTZ.MSG Insert Into DFTZ

DB2 Import To C: /DFTZ.IXF of IXF Commitcount 5000 Messages C: /DFTZ.MSG Insert Into DFTZ

DB2 Import to C: /DFTZ.IXF of IXF Commitcount 5000 Insert Into DFTZ

DB2 Import To C: /DFTZ.IXF of IXF Commitcount 5000 Insert_Update INTO DFTZDB2 Import To C: /DFTZ.IXF of IXF Commitcount 5000 Replace Into DFTZ

DB2 Import to C: /DFTZ.IXF of ixf commitcount 5000 create Into DFTZ (IXF only)

DB2 Import to C: /DFTZ.IXF of ixf commitcount 5000 replace_create INTO DFTZ (IXF only)

15. Perform a batch file

DB2 -TF batch file name

(Each command in the file is used; end)

16. Automatically generate batch files

Building a text file: Temp.sql

Select 'Runstats on Table DB2.' || TabName || 'with Distribution and Detailed Indexes All;' from syscat.tables where tabschema = 'DB2' and type = 't';

DB2 -TF TEMP.SQL> Runstats.sql

17. Automatic generation table (view) statement

On the server: c: / sqllib / misc directory

DB2 Connect To O_YD User DB2 Using PWD

DB2LOOK -D O_YD -U DB2 -E -P -C C: /o_yd.txt

18. Empower users

Grant DBADM on Database to User BB

19. Show the first record

Select * from czyxx fetch first 1 ROWS ONLY (invalid in SP)

20. Show all of the current users

DB2LOOK -D YLBX -U DB2ADMIN -W -ASD -A -E -O A.txt21.

twenty one. List all system tables

List table for system

twenty two. View the table structure

DB2 DESCRIBE SELECT * from User.tables

TOPAS View processes and CPUs, hard drive usage.

DB2 error code

SQL10007N failed to retrieve the message "". Cause code: "".

Explanation: Unable to retrieve the requested message from the message file . Cause code

Is one of the following:

1. Environment variable "db2instance"

Examples not set or set to invalid. Correct it and try again.

2. Find the message file, but the file cannot be opened due to permissions.

Check the file permission of the file in the message directory.

3. Failure to find message files. This file does not exist or the directory where the message file is located does not exist.

Check if the 'prime' directory (default) or the directory with the 'LANG' environment variable is existing in the message directory.

4. The requested message does not exist in the message file.

The message file is outdated, or it is an incorrect message file.

5. LC_CTYPE is set to a language environment that does not support the database.

Correct it and try again.

6. An unexpected system error.

Try again. If the problem still exists, contact the IBM representative.

7. Insufficient memory. Try to get dedicated memory failure.

Try again.

User Response: After verifying the following, re-issue this command:

o Make sure the DB2Instance environment variable is set to the correct text string O to ensure that the user name attempts this command is specified (ie in / etc / psaawd file)

o On the username attempt to this command, make sure the LANG environment variable is set to the correct value to the installed language, or set to

'C' (default is any value in 'prime' directory)

If the above is correct, the error still occurs, then reinstall DB2.

How to establish a database management (DMS) table space on AIX

1. Use the mklv command to make naked devices, the syntax is:

MKLV -T JFS -Y Equipment Name -u User Name -g Group Name VG Name LV Size Hard Disk

For example: mklv -t jfs -y contert -u db2inst1 -g db2iadm1 rootvg 10 hdisk0

2. Create a table space

1). Connect the database

2) Create a table space: Note To the quotation number in the command:

DB2 "CREATE TABLESPACE Table Space Name Managed by Database Using (Device Naked Device Name and Path Size)

For example: DB2 "CREATE TABLESPACE TPTEST Managed by Database Using (Device '/ dev / rconte' 80m)

How to view the modified instance and database configuration parameters in the command line

View the configuration parameters of the instance in the command line, can be implemented with the DB2 Get DBM CFG command.

Similarly, the DB2 GET DB CFG FOR database name can be used to obtain the configuration parameters of the database.

The following is a part of the database parameters:

Log file size (4KB) (logfilsiz) = 250

Number of Primary Log Files (Logprimary) = 3

Number of Secondary Log Files (LogSecond) = 2

Modify instance configuration parameters, use DB2 Update DBM CFG Using Parameter Name New Value

Similarly, use the DB2 UPDATE DB CFG for Database name using parameter name new value to modify the database configuration parameters.

For example, to modify the LogPrimary in the Sample database configuration parameter, you can use the following command:

DB2 UPDATE DB CFG for Sample Using Logprimary 10

How to avoid the log space error when using the import command to enter the data to the database?

When executing the import command, if you use a loop log, you sometimes have a log full error, and you can solve it with the commcount parameter.

Because the log space is often because all logs are active. After the commit execution, the occupied resources will be released, including logs. In this way, the log used by the current transaction is executed after the commit command is executed, that is, it becomes a non-active state.

Check the SP using a table

select PROCNAME from SYSCAT.PROCEDURES where SPECIFICNAME in (select dname from sysibm.sysdependencies where bname in (select pkgname from syscat.packagedep where bname like 'tb_realtime_rec_ctr%')) with ur

Configure IBM DB2 universal database to build SQL procedures

Introduction

IBM DB2? UDB VERSION 7 introduces SQL procedures as one of them. The SQL process refers to the stored procedure written in SQL language. This article discusses the process of setting an environment to build and deploy the SQL process. After converting the SQL process into a C language code, build the code to build a stored procedure library. These SQL processes are supported on Windows?, OS / 2?, UNIX?, OS / 390? And OS / 400? This article is related to Windows, OS / 2 and UNIX platforms. prerequisites

To build a SQL process on a machine, you need to install two products:

1. Application Development Client (ADC), which contains all libraries, header files, precompilers, and more required to develop DB2 applications.

2. A C compiler that supports DB2.

Check the Application Building Guide for the list of the Support DB2 provided by the platform.

Set the environment

As mentioned earlier, DB2 converts the SQL process into c code, which is then compiled into a stored procedure library. In order to compile this code, DB2 must be configured to detect the installed C compiler.

In order to configure DB2 to detect the installed C compiler:

1. Create an executable to set the environment for the compiler. This file will be a batch (.bat) file on Windows, the command (.cmd) file on OS / 2 or the shell script on UNIX. Setting the compiler environment will include updating the Path, include, and LIB environment variables.

2. Update the DB2 Registry Variable DB2_SQLROUTINE_COMPILER_PATH to point to the executable created by step 1 by issuing the following command:

DB2SET DB2_SQLROUTINE_COMPILER_PATH = FULL_PATH_TO_EXECUTABLE_FILE

Note: On Windows NT? And Windows 2000, you do not need to set the above registry variable as long as the compiler's environment variables have been saved by the System variable.

DB2 also provides default executables on each platform that sets the environment for one of the (default) compilers supported by the platform. Its default file name and location depends on the platform:

On Windows:% db2path% // Sqllib // Function // Routine // SR_CPath.bat

On OS / 2:% db2path% // sqllib // function // routine // sr_cpath.cmd

On UNIX: $ home / sqllib / function / routine / sr_cpath

By default, DB2 sets DB2_sqlroutine_compiler_path to one of the files, unless you have modified its registry variable to point to a different file. Therefore, if the default C compiler is installed and intended to be used to develop, there is no need to create a separate executable to set the compiler environment.

The content of the above files should be checked to ensure that they correctly reflect the environment settings of the default compiler in the focus platform. For example, on Windows NT and Windows 2000, the SR_CPATH.BAT file assumes that Microsoft Visual C ? Version 6 is installed under C: // Program Files // Microsoft Visual Studio. If it is installed under D: // Microsoft Visual Studio, then the content of the file needs to be modified.

Another common error is to make all correct modifications to the file, but retain the annotations around the compiler environment setting command. Check the contents of the sr_cpath.bat file again, you will notice that all rows in the file start with the REM key. The REM key is used for the beginning of the comment line, so it should be deleted to set the compiler environment. Compile conversion C code

After the DB2 is configured to detect the compiler environment, you need to configure it to use the compile command for the installed compiler. This will be done by setting another DB2 registry variable db2_sqlroutine_compile_command to the compiler of the installed compiler. DB2_SQLROUTINE_COMPILE_COMMAND will be set to a default compile command for the default compiler on the platform. The following is an example of the default compile command on the AIX?, Solaris? And Windows platform:

On AIX, the default compile command for IBM C Set for AIX Version 3.6.6 is:

XLC_R - -H512 -T512 -i $ homen / sqllib / include sqlroutine_filename.c //

-be: SQLROUTINE_FILENAME.EXP -E SQLROUTINE_ENTRY / /

-o sqlroutine_filename -l $ homen / SQLLIB / lib -lc-ldb2

On Solaris, the default compile command for SPARC Compiler C Version 4.2 and 5.0 is:

CC - # -kpic -i $ home / sqllib / include sqlroutine_filename.c -g //

-o SQLROUTINE_FILENAME -L $ HOME / SQLLIB / LIB -R $ HOME / SQLLIB / LIB -LDB2

On Windows, the default compile command for Microsoft Visual C Version 5.0 and 6.0 is:

CL -OD -W2 / TC -D_X86_ = 1 -i% DB2PATH% // include Sqlroutine_FileName.c

/ link -dll -def: SQLROUTINE_FILENAME.DEF /Oout:sqlroutine_filename.dll

% DB2PATH% // lib // db2api.lib

Note: The '/' on the above AIX and Solaris platforms is used to indicate the carriage return. For the Windows platform, its entire command is a continuous line, no '/' to indicate the carriage.

Customized compile command

If you install different compilers (thus requires different compile commands), or if you customize the default compilation option, you need to set DB2_SQLROUTINE_COMPILE_COMMAND to a customized compile command. The following example shows how to specify debug options (to return to debug information) each of the default compile commands shown above:

To return to debug information on the AIX platform, you must add the -g option in the default compile command and update db2_sqlroutine_compile_command, as shown below:

DB2SET DB2_SQLROUTINE_COMPILE_COMMAND = 撺 LC_R - -H512 -T512 -G //

-I $ homen / SQLLIB / include Sqlroutine_FileName.c //

-be: SQLROUTINE_FILENAME.EXP -E SQLROUTINE_ENTRY / /

-o sqlroutine_filename -l $ homen / SQLLIB / lib -lc-ldb2

To return to debug information on the Solaris platform, you should add -g options in the default compile command and update db2_sqlroutine_compile_commad, as shown below: DB2SET DB2_SQLROUTINE_COMPILE_COMMAND = 攃 C - # -kpic -g //

-I $ home / sqllib / include sqlroutine_filename.c -g ////

-o SQLROUTINE_FILENAME -L $ HOME / SQLLIB / LIB -R $ HOME / SQLLIB / LIB -LDB2

To return to debug information on a Windows platform, update db2_sqlroutine_compile_command, as shown below:

DB2SET DB2_SQLROUTINE_COMPILE_COMMAND = CL-CW2 / TC -D_X86_ = 1

-I% db2path% // include sqlroutine_filename.c / link -dll

-def: SQLROUTINE_FILENAME.DEF /Oout:sqlroutine_filename.dll

-debug: full -pdb: none -debugType: CV% db2path% // lib // db2api.lib

Again Please note that on the Windows platform, the compile command should be entered in a line.

Restore the default compile command

Setting DB2_SQLROUTINE_COMPILE_COMMAND to empty will resume the default compile commands and options. Its settings are as follows:

DB2SET DB2_SQLROUTINE_COMPILE_COMMAND =

Conclude

There are two main steps to build a SQL process:

1. Install the compiler and configure DB2 to detect the compiler environment. This is done by creating executables for setting up a compiler environment (Path, LIB and Include environment variables) and set DB2_SQLROUTINE_COMPILER_PATH to this file. You can use the default executable (SR_CPATH / SR_CPATH.BAT / SR_CPATH.CMD) or create a new file to set the compiler environment for different compilers.

2. Set DB2_SQLROUTINE_COMPILE_COMMAND to a compile command. You can use the default compilation command or set DB2_SQLROUTINE_COMPILE_COMMAND to a customized compile command (for example, add a test option, 64-bit option, etc.).

Build a common error in the SQL process derived from the error configuration of the compiler environment. This paper concludes the process of setting the environment for building a SQL process. DB2 Version 7, version of FixPak 3 provides more examples of default compile commands on other platforms.

转载请注明原文地址:https://www.9cbs.com/read-18329.html

New Post(0)