<DB2>《Some precautions during use of DB2》

1 When building a stored procedure, the TAB key cannot be used after Create

create procedure 

Only spaces can be used after create, and the tab key cannot be used, otherwise the compilation will fail.

2 View statement execution plan

dynexpln -d testdb -f test.sql -o test.out -g -z ';' 

The sql statement is placed in test.sql, and the results are output to test.out.

3 View the SP stored procedure execution plan

db2expln -c kstar -d testdb -o test.out -p P2806220 -s 0

-p is the id of the stored procedure

4 Manually configure the database alias and remove the alias configuration

db2 catalog db gtjazb on /gtjadb2(目录) 
db2 uncatalog db gtjazb

5 View and stop the current application of the database

db2 list applications show detail 

Authorization ID | Application name | Application handle | Application ID | Serial number # | Agent | Coordinator | Status | Status change time | DB name | DB path | | Node number | pid/thread

1. The first part of the application identifier is the IP address of the application, but it is expressed in hexadecimal.
2. pid/thread is the thread number seen under unix

Stop application: :The 236 is the application handle under viewing

db2 "force application(236)" 
db2 “force application all

6 Change the size of dbheap

db2 update db cfg for testdb using DBHEAP 4096 

The value is for db. Dbheap>catalogcache_sz+logbufsz

7 Change the size of catalogcache

db2 update db cfg for testdb using catalogcache 2048 

is related to the number of tables and fields. If there are many tables and fields, it is best to change this indicator
to be larger. The size of this value can be set to be equal to the size of the table creation script, or slightly larger.
Of course, if there is a dynamically created table, it may be larger depending on the actual situation.

8 Change tool heap size

UTIL_HEAP_SZ
This indicator value is used to allocate memory for tools such as import, export, and load.

9 Change the size of the sort heap

db2 update db cfg for testdb using SORTHEAP 2048 

Change the size of the sort heap to 2048 pages. For applications with a lot of queries, it is best to set this value
to a larger value.
This indicator value is the memory allocated for each connection. If there are many connections, be careful not to
set it too high. If you see sort overflow, you can increase the value.
This memory is only applied for when it is used, and will not be applied for normally.

10 Change the size of stmtheap

db2 update db cfg for head using STMTHEAP 4096 

This indicator value is the memory allocated for each connection. If there are many connections, be careful not to set it too high
. This data value is related to the explanation statement. If it is too small, a larger statement may not be able to explain it. This memory is only applied for when it is used, and will not be applied for normally.

11 Change the size of lock-related parameters

db2 update db cfg for head using LOCKLIST 40000 

This is the memory occupied by the maximum lock resource of the entire db. The consumption of lock resources is that each shared lock
occupies 36 bytes, and the exclusive lock occupies 72 bytes. The size of the lock resource should be set with the application in mind.

db2 update db cfg for head using MAXLOCKS 10 

This parameter is to set the maximum lock resource that a single application can use. This is a percentage
ratio. The actual size of the lock resource that a single application can use is
LOCKLIST* MAXLOCKS

db2 update db cfg for head using LOCKTIMEOUT 60 

This parameter is to set the maximum time for the application lock to wait. The unit is seconds. The
setting of this value should be more appropriate. In the case of more concurrency, lock waiting may be inevitable. For example,
if If not set appropriately, too many time out errors may occur.

db2 update db cfg for head using DLCHKTIME 10000 

This parameter is to set the time for the system to detect deadlock. The unit is milliseconds. Do not set
too small, which consumes system resources and is not necessary

12 Eliminate version problems after upgrading

db2 bind @db2ubind.lst 
db2 bind @db2cli.lst

13. Run the runstats and rebind packages after the database performance drops.

After the number of records in the table (large table) changes30%, you should do a runstats
From the perspective of convenient management, Build the script directly from syscat.tables.

 db2 “select 'runstats on table db2inst1.' || tabname || ' and indexes all' from syscat.tables where tabschema='DB2INST1' and type='T'>stats.sql 

After removing the redundant information from stats.sql, run the script.

db2 -tvf stats.sql 

请注意在做 runstats 时,将其他应用全部断开。
In order to improve the speed, you can adjust the parameters of the database and expand applheapsz,
sortheadp, stmtheap by 10 times first, but be careful to restore the parameters after rebind.

Note: After completing runstats, if the related sp is not rebind, there will be no change in performance and new statistics will not be used for calculation.

db2 “select 'rebind package '||pkgname from syscat.packages where pkgschema='DB2INST1’ “ >rebind.sql 

After removing the redundant information from stats.sql, run the script.

db2 -tvf rebind.sql

15 Fix the use of diagnostic database db2dart

 db2dart testdb
  //对一个表做诊断(从这里可以得到该表的 index 的 id号) 
db2dart testdb/T 
  //对一个表的 index 做修复 
db2dart gtjazb /MI

db2dart also has some functions, but db2dart is a relatively deep usage and should not be used under normal circumstances. See the help for details.

16 Obtain database information using db2support

db2support /gtja_emc/dream/ -d testdb

17 knowledge about locks

When db2 get snapshot for Locks on head >snap.log, you often see some
lock types, which are not very clear:
S: share lock, shared lock, after adding, other applications can read, but cannot update,
Each occupies 36 bytes.
X: exclusive, exclusive lock. After adding it, other programs cannot read it unless they use UR isolation level.
Each takes 72 bytes.

**** 表锁 
IN (Intenet None)不需要行锁 
IS (Intent Share) 需要行锁配合 
IX (Intent eXclusive) 需要行锁配合 
SIX (Share with Intent exclusive)需要行锁,共享排他锁 
S (Share) 不需要行锁配合 
U (Update) 不需要行锁配合 
X (eXclusive) 不需要行锁配合 
Z (Super Exclusive)不需要行锁配合 
***** 行锁 
S (Share)共享锁 
U (Update) 更改锁 
X (eXclusive) 排他锁 
W (Weak eXclusive)弱排他锁 
NS (Next Key Share) 下一行共享锁 
NX (Next Key eXclusive)下一行排他锁 
NW (Next Key Weak eXclusive)下一行弱排他锁

Superposition of locks:
S lock and S lock can be added to an object by multiple programs.
X locks and S locks are incompatible.

Object Type= Row (行锁)
Object Type= Table (表锁)
Object Type= Key Value
Object Type= Internal P Lock
Object Type= Internal V Lock
Object Type= Internal C Lock

Guess you like

Origin blog.csdn.net/tangcoolcole/article/details/134902053
db2
db2