db2 查看一个连接正在执行的sql
由于很多数据库在配置的时候并没有打开一些相应的监控,导致像 sql statement等信息监控不到 :
[db2inst1@bbbbbb ~]$ db2 get monitor switches
Monitor Recording Switches
Switch list for db partition number 0
Buffer Pool Activity Information (BUFFERPOOL) = OFF
Lock Information (LOCK) = OFF
Sorting Information (SORT) = OFF
SQL Statement Information (STATEMENT) = OFF
Table Activity Information (TABLE) = OFF
Take Timestamp Information (TIMESTAMP) = ON 08/05/2014 13:46:29.025315
Unit of Work Information (UOW) = OFF
[db2inst1@bbbbbb ~]$
[db2inst1@bbbbbb ~]$ db2 list applications
Auth Id Application Appl. Application Id DB # of
Name Handle Name Agents
-------- -------------- ---------- -------------------------------------------------------------- -------- -----
DB2INST1 db2bp 7 *LOCAL.db2inst1.140805054702 BBB 1
[db2inst1@bbbbbb ~]$ db2 list applications show detail
CONNECT Auth Id Application Name Appl. Application Id Seq# Number of Coordinating DB Coordinator Status Status Change Time DB Name DB Path
Handle Agents partition number pid/thread
-------------------------------------------------------------------------------------------------------------------------------- -------------------- ---------- -------------------------------------------------------------- ----- ---------- ---------------- --------------- ------------------------------ -------------------------- -------- --------------------
DB2INST1 db2evmg_DB2DETAILDEA 13 *LOCAL.DB2.140805054716 00001 1 0 38 Connect Completed Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2fw0 12 *LOCAL.DB2.140805054715 00001 1 0 37 Connect Completed Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2lused 11 *LOCAL.DB2.140805054714 00001 1 0 36 UOW Waiting Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2wlmd 10 *LOCAL.DB2.140805054713 00001 1 0 35 Connect Completed Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2taskd 9 *LOCAL.DB2.140805054712 00001 1 0 34 UOW Waiting Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2stmm 8 *LOCAL.DB2.140805054711 00001 1 0 33 UOW Waiting Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
DB2INST1 db2bp 7 *LOCAL.db2inst1.140805054702 00005 1 0 19 UOW Executing Not Collected BBB /db2data/database/db2inst1/NODE0000/SQL00001/
[db2inst1@bbbbbb ~]$
#### 对单个application 查看正在执行的sql 。。。结果就是查不到
[db2inst1@bbbbbb ~]$ db2 get snapshot for application agentid 7
Application Snapshot
Application handle = 7
Application status = Rollback to Savepoint
Start Time = 08/05/2014 14:45:06.238860
Completed Work = 60746995 bytes
Total Work = 241631957 bytes
Status change time = Not Collected
Application code page = 1208
Application country/region code = 1
DUOW correlation token = *LOCAL.db2inst1.140805054702
Application name = db2bp
Application ID = *LOCAL.db2inst1.140805054702
Sequence number = 00005
TP Monitor client user ID =
TP Monitor client workstation name =
TP Monitor client application name =
TP Monitor client accounting string =
Connection request start timestamp = 08/05/2014 13:47:02.604023
Connect request completion timestamp = 08/05/2014 13:47:11.489247
Application idle time = Not Collected
CONNECT Authorization ID = DB2INST1
Client login ID = db2inst1
Configuration NNAME of client = bbbbbb
Client database manager product ID = SQL09078
Process ID of client application = 3755
Platform of client application = LINUXAMD64
Communication protocol of client = Local Client
Inbound communication address = *LOCAL.db2inst1
Database name = BBB
Database path = /db2data/database/db2inst1/NODE0000/SQL00001/
Client database alias = BBB
Input database alias =
Last reset timestamp =
Snapshot timestamp = 08/05/2014 14:46:12.177716
Authorization level granted =
User authority:
DBADM authority
SECADM authority
DATAACCESS authority
ACCESSCTRL authority
Group authority:
SYSADM authority
CREATETAB authority
BINDADD authority
CONNECT authority
IMPLICIT_SCHEMA authority
Coordinating database partition number = 0
Current database partition number = 0
Coordinator agent process or thread ID = 19
Current Workload ID = 1
Agents stolen = 0
Agents waiting on locks = 0
Maximum associated agents = 1
Priority at which application agents work = 0
Priority type = Dynamic
Lock timeout (seconds) = -1
Locks held by application = 3
Lock waits since connect = 0
Time application waited on locks (ms) = Not Collected
Deadlocks detected = Not Collected
Lock escalations = 5
Exclusive lock escalations = 5
Number of Lock Timeouts since connected = 0
Total time UOW waited on locks (ms) = Not Collected
Total sorts = 0
Total sort time (ms) = Not Collected
Total sort overflows = 0
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool data writes = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index physical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Buffer pool index writes = Not Collected
Buffer pool xda logical reads = Not Collected
Buffer pool xda physical reads = Not Collected
Buffer pool temporary xda logical reads = Not Collected
Buffer pool temporary xda physical reads = Not Collected
Buffer pool xda writes = Not Collected
Total buffer pool read time (milliseconds) = Not Collected
Total buffer pool write time (milliseconds)= Not Collected
Time waited for prefetch (ms) = Not Collected
Unread prefetch pages = Not Collected
Direct reads = Not Collected
Direct writes = Not Collected
Direct read requests = Not Collected
Direct write requests = Not Collected
Direct reads elapsed time (ms) = Not Collected
Direct write elapsed time (ms) = Not Collected
Number of SQL requests since last commit = 1
Commit statements = 2
Rollback statements = 2
Dynamic SQL statements attempted = 5
Static SQL statements attempted = 4
Failed statement operations = 2
Select SQL statements executed = 0
Xquery statements executed = 0
Update/Insert/Delete statements executed = 5
DDL statements executed = 0
Inactive stmt history memory usage (bytes) = 0
Internal automatic rebinds = 0
Internal rows deleted = 0
Internal rows inserted = 0
Internal rows updated = 0
Internal commits = 1
Internal rollbacks = 0
Internal rollbacks due to deadlock = 0
Binds/precompiles attempted = 0
Rows deleted = 0
Rows inserted = 2016187
Rows updated = 0
Rows selected = 0
Rows read = 4389491
Rows written = 4389307
UOW log space used (Bytes) = Not Collected
Previous UOW completion timestamp = Not Collected
Elapsed time of last completed uow (sec.ms)= Not Collected
UOW start timestamp = Not Collected
UOW stop timestamp = Not Collected
UOW completion status = Not Collected
Open remote cursors = 0
Open remote cursors with blocking = 0
Rejected Block Remote Cursor requests = 0
Accepted Block Remote Cursor requests = 0
Open local cursors = 0
Open local cursors with blocking = 0
Total User CPU Time used by agent (s) = 56.546219
Total System CPU Time used by agent (s) = 0.000000
Host execution elapsed time = Not Collected
Package cache lookups = 5
Package cache inserts = 1
Application section lookups = 5
Application section inserts = 1
Catalog cache lookups = 17
Catalog cache inserts = 11
Catalog cache overflows = 0
Catalog cache high water mark = 0
Workspace Information
Most recent operation = Execute Immediate
Most recent operation start timestamp = Not Collected
Most recent operation stop timestamp = Not Collected
Agents associated with the application = 1
Number of hash joins = 0
Number of hash loops = 0
Number of hash join overflows = 0
Number of small hash join overflows = 0
Number of OLAP functions = 0
Number of OLAP function overflows = 0
Memory usage for application:
Memory Pool Type = Application Heap
Current size (bytes) = 65536
High water mark (bytes) = 65536
Configured size (bytes) = 1048576
Agent process/thread ID = 19
Agent Lock timeout (seconds) = -1
Memory usage for agent:
Memory Pool Type = Other Memory
Current size (bytes) = 524288
High water mark (bytes) = 589824
Configured size (bytes) = 1051570176
[db2inst1@bbbbbb ~]$
#### 对于这样的情况就可以用其他方式来找出一个连接正在执行的sql :
[db2inst1@bbbbbb ~]$ db2pd -applications -dynamic -d bbb #### 直接输出连接上来的application 和 动态sql
Database Partition 0 -- Database BBB -- Active -- Up 0 days 01:25:49 -- Date 2014-08-05-15.12.51.315617
Applications:
Address AppHandl [nod-index] NumAgents CoorEDUID Status C-AnchID C-StmtUID L-AnchID L-StmtUID Appid WorkloadID WorkloadOccID CollectActData CollectActPartition CollectSectionActuals
0x0000000201090080 13 [000-00013] 1 38 ConnectCompleted 0 0 0 0 *LOCAL.DB2.140805054716 0 0 N C N
0x0000000201060080 12 [000-00012] 1 37 ConnectCompleted 0 0 0 0 *LOCAL.DB2.140805054715 0 0 N C N
0x0000000201050080 11 [000-00011] 1 36 UOW-Waiting 0 0 0 0 *LOCAL.DB2.140805054714 0 0 N C N
0x0000000201030080 10 [000-00010] 1 35 ConnectCompleted 0 0 0 0 *LOCAL.DB2.140805054713 0 0 N C N
0x0000000201010080 9 [000-00009] 1 34 UOW-Waiting 0 0 0 0 *LOCAL.DB2.140805054712 0 0 N C N
0x0000000200FF0080 8 [000-00008] 1 33 UOW-Waiting 0 0 0 0 *LOCAL.DB2.140805054711 0 0 N C N
0x0000000200F80080 7 [000-00007] 1 19 UOW-Executing 691 1 691 1 *LOCAL.db2inst1.140805054702
Dynamic SQL Statements:
Address AnchID StmtUID NumEnv NumVar NumRef NumExe Text
0x00002AAAD72D4E00 111 1 1 1 1 1 SELECT POLICY FROM
SYSTOOLS.POLICY WHERE MED='DB2TableMaintenanceMED' AND DECISION='TableRunstatsDecision' AND NAME='TableRunstatsPolicy'
0x00002AAADA1B35E0 164 1 1 1 19 19 SELECT COLNAME, TYPENAME FROM
SYSCAT.COLUMNS WHERE TABNAME='POLICY' AND TABSCHEMA='SYSTOOLS'
0x00002AAAD72F4D40 167 1 1 1 1 1 SELECT IBM.TID, IBM.FID FROM
SYSIBM.SYSTABLES AS IBM, SYSTOOLS.HMON_ATM_INFO AS ATM WHERE ATM.STATS_FLAG <> 'Y' AND IBM.TYPE IN ( 'S', 'T' ) AND
ATM.CREATE_TIME = IBM.CTIME AND ATM.SCHEMA = IBM.CREATOR AND ATM.NAME = IBM.NAME ORDER BY IBM.FID, IBM.TID WITH UR
0x00002AAAD72F4800 332 1 1 1 1 1 UPDATE SYSTOOLS.HMON_ATM_INFO
AS ATM SET STATS_FLAG = 'N', REORG_FLAG = 'N' WHERE (ATM.SCHEMA, ATM.NAME) IN (SELECT IBM.CREATOR, IBM.NAME
FROM SYSIBM.SYSTABLES AS IBM WHERE IBM.TYPE = 'N' )
0x00002AAAD72CB280 340 1 1 1 2 2 SELECT TABNAME FROM
SYSCAT.TABLES WHERE TABNAME='HMON_ATM_INFO' AND TABSCHEMA='SYSTOOLS'
0x00002AAADA1B4940 450 1 1 1 19 19 SELECT TRIGNAME FROM
SYSCAT.TRIGGERS WHERE TABNAME='POLICY' AND TABSCHEMA='SYSTOOLS'
0x00002AAAD72D3CC0 462 1 1 1 149 149 SELECT CREATE_TIME FROM
SYSTOOLS.HMON_ATM_INFO WHERE SCHEMA = ? AND NAME = ? FOR UPDATE
0x00002AAAD72D4360 501 1 1 1 1 2 INSERT INTO
SYSTOOLS.HMON_ATM_INFO ( SCHEMA, NAME, CREATE_TIME ) VALUES ( ?, ?, ? )
0x00002AAADA1AF7E0 580 1 1 1 19 19 CALL
SYSPROC.SYSINSTALLOBJECTS('POLICY','V','','')
0x00002AAAD72D4860 639 1 1 1 1 1 DELETE FROM
SYSTOOLS.HMON_ATM_INFO AS ATM WHERE NOT EXISTS ( SELECT * FROM SYSIBM.SYSTABLES AS IBM WHERE ATM.NAME = IBM.NAME AND
ATM.SCHEMA = IBM.CREATOR AND ATM.CREATE_TIME = IBM.CTIME ) WITH UR
0x00002AAADA1A53C0 691 1 1 1 6 6 insert into t3 select * from
t3
0x00002AAAD72F4320 734 1 1 1 1 1 UPDATE SYSTOOLS.HMON_ATM_INFO
AS ATM SET ATM.STATS_FLAG = 'Y'
0x00002AAAD72C7920 735 1 1 1 2 2 CALL SYSINSTALLOBJECTS(
'DB2AC', 'V', NULL, NULL )
0x00002AAAD72D37C0 766 1 1 1 1 1 SELECT CREATOR, NAME, CTIME
FROM SYSIBM.SYSTABLES WHERE TYPE='T' OR TYPE='S' OR TYPE='N' WITH UR
0x00002AAAD72C50C0 809 1 1 1 51 51 SET CURRENT LOCK TIMEOUT 5
0x00002AAAD72D3180 876 1 1 1 1 1 UPDATE SYSTOOLS.HMON_ATM_INFO
SET STATS_LOCK = 'N', REORG_LOCK = 'N'
0x00002AAAD72CF4C0 886 1 1 1 2 2 SELECT TABNAME FROM
SYSCAT.TABLES WHERE TABNAME='HMON_COLLECTION' AND TABSCHEMA='SYSTOOLS'
0x00002AAAD730A6E0 1014 1 1 1 17 17 SELECT POLICY FROM
SYSTOOLS.POLICY WHERE MED='DB2CommonMED' AND DECISION='NOP' AND NAME='CommonPolicy'
***** db2pd -applications 中的 L-AnchID 值 与 db2pd -dynamic 中的 AnchID 是一样的。 (如我这里的例子是 691 )
You can use the anchor ID (AnchID) value that identified the dynamic SQL statement to identify the associated application. The results show that the last anchor ID (L-AnchID) value is the same as the anchor ID (AnchID) value. You use the results from one run of db2pd in the next run of db2pd.
所以这也是一种方法 ~
##### 打开实例级别监控
[db2inst1@bbbbbb ~]$ db2 get dbm cfg |grep -i DFT_MON_STMT
Statement (DFT_MON_STMT) = OFF
[db2inst1@bbbbbb ~]$ db2 update dbm cfg using DFT_MON_STMT ON
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
[db2inst1@bbbbbb ~]$ db2 get dbm cfg |grep -i DFT_MON_STMT
Statement (DFT_MON_STMT) = ON
[db2inst1@bbbbbb ~]$
### 重新连接发现,实例级别监控打开后 ,session 级别也相应打开
[db2inst1@bbbbbb ~]$ db2 get monitor switches
Monitor Recording Switches
Switch list for db partition number 0
Buffer Pool Activity Information (BUFFERPOOL) = OFF
Lock Information (LOCK) = OFF
Sorting Information (SORT) = OFF
SQL Statement Information (STATEMENT) = ON 08/05/2014 15:30:28.476221
Table Activity Information (TABLE) = OFF
Take Timestamp Information (TIMESTAMP) = ON 08/05/2014 13:46:29.025315
Unit of Work Information (UOW) = OFF
### 再次查看一个application 上的sql ,就能监控的到了。
[db2inst1@bbbbbb ~]$ db2 get snapshot for application agentid 7
Application Snapshot
Application handle = 7
Application status = UOW Executing
Status change time = Not Collected
Application code page = 1208
Application country/region code = 1
DUOW correlation token = *LOCAL.db2inst1.140805054702
Application name = db2bp
Application ID = *LOCAL.db2inst1.140805054702
Sequence number = 00007
TP Monitor client user ID =
TP Monitor client workstation name =
TP Monitor client application name =
TP Monitor client accounting string =
Connection request start timestamp = 08/05/2014 13:47:02.604023
Connect request completion timestamp = 08/05/2014 13:47:11.489247
Application idle time =
CONNECT Authorization ID = DB2INST1
Client login ID = db2inst1
Configuration NNAME of client = bbbbbb
Client database manager product ID = SQL09078
Process ID of client application = 3755
Platform of client application = LINUXAMD64
Communication protocol of client = Local Client
Inbound communication address = *LOCAL.db2inst1
Database name = BBB
Database path = /db2data/database/db2inst1/NODE0000/SQL00001/
Client database alias = BBB
Input database alias =
Last reset timestamp =
Snapshot timestamp = 08/05/2014 15:31:46.291150
Authorization level granted =
User authority:
DBADM authority
SECADM authority
DATAACCESS authority
ACCESSCTRL authority
Group authority:
SYSADM authority
CREATETAB authority
BINDADD authority
CONNECT authority
IMPLICIT_SCHEMA authority
Coordinating database partition number = 0
Current database partition number = 0
Coordinator agent process or thread ID = 19
Current Workload ID = 1
Agents stolen = 0
Agents waiting on locks = 0
Maximum associated agents = 1
Priority at which application agents work = 0
Priority type = Dynamic
Lock timeout (seconds) = -1
Locks held by application = 3
Lock waits since connect = 0
Time application waited on locks (ms) = Not Collected
Deadlocks detected = Not Collected
Lock escalations = 6
Exclusive lock escalations = 6
Number of Lock Timeouts since connected = 0
Total time UOW waited on locks (ms) = Not Collected
Total sorts = 0
Total sort time (ms) = Not Collected
Total sort overflows = 0
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool data writes = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index physical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Buffer pool index writes = Not Collected
Buffer pool xda logical reads = Not Collected
Buffer pool xda physical reads = Not Collected
Buffer pool temporary xda logical reads = Not Collected
Buffer pool temporary xda physical reads = Not Collected
Buffer pool xda writes = Not Collected
Total buffer pool read time (milliseconds) = Not Collected
Total buffer pool write time (milliseconds)= Not Collected
Time waited for prefetch (ms) = Not Collected
Unread prefetch pages = Not Collected
Direct reads = Not Collected
Direct writes = Not Collected
Direct read requests = Not Collected
Direct write requests = Not Collected
Direct reads elapsed time (ms) = Not Collected
Direct write elapsed time (ms) = Not Collected
Number of SQL requests since last commit = 1
Commit statements = 2
Rollback statements = 4
Dynamic SQL statements attempted = 7
Static SQL statements attempted = 6
Failed statement operations = 4
Select SQL statements executed = 0
Xquery statements executed = 0
Update/Insert/Delete statements executed = 7
DDL statements executed = 0
Inactive stmt history memory usage (bytes) = 0
Internal automatic rebinds = 0
Internal rows deleted = 0
Internal rows inserted = 0
Internal rows updated = 0
Internal commits = 1
Internal rollbacks = 0
Internal rollbacks due to deadlock = 0
Binds/precompiles attempted = 0
Rows deleted = 0
Rows inserted = 2526037
Rows updated = 0
Rows selected = 0
Rows read = 5856242
Rows written = 5856057
UOW log space used (Bytes) = Not Collected
Previous UOW completion timestamp = Not Collected
Elapsed time of last completed uow (sec.ms)= Not Collected
UOW start timestamp = Not Collected
UOW stop timestamp = Not Collected
UOW completion status = Not Collected
Open remote cursors = 0
Open remote cursors with blocking = 0
Rejected Block Remote Cursor requests = 0
Accepted Block Remote Cursor requests = 0
Open local cursors = 0
Open local cursors with blocking = 0
Total User CPU Time used by agent (s) = 82.716163
Total System CPU Time used by agent (s) = 0.000000
Host execution elapsed time = 0.000000
Package cache lookups = 7
Package cache inserts = 1
Application section lookups = 7
Application section inserts = 1
Catalog cache lookups = 17
Catalog cache inserts = 11
Catalog cache overflows = 0
Catalog cache high water mark = 0
Workspace Information
Most recent operation = Execute Immediate
Most recent operation start timestamp = 08/05/2014 15:31:36.831300
Most recent operation stop timestamp =
Agents associated with the application = 1
Number of hash joins = 0
Number of hash loops = 0
Number of hash join overflows = 0
Number of small hash join overflows = 0
Number of OLAP functions = 0
Number of OLAP function overflows = 0
Statement type = Dynamic SQL Statement
Statement = Execute Immediate
Section number = 203
Application creator = NULLID
Package name = SQLC2H23
Consistency Token =
Package Version ID =
Cursor name =
Statement database partition number = 0
Statement start timestamp = 08/05/2014 15:31:36.831300
Statement stop timestamp =
Elapsed time of last completed stmt(sec.ms)= 0.000000
Total Statement user CPU time = 1.697368
Total Statement system CPU time = 0.000000
SQL compiler cost estimate in timerons = 10462
SQL compiler cardinality estimate = 9888
Degree of parallelism requested = 1
Number of agents working on statement = 1
Number of subagents created for statement = 1
Statement sorts = 0
Total sort time = 0
Sort overflows = 0
Rows read = 324068
Rows written = 324068
Rows deleted = 0
Rows updated = 0
Rows inserted = 0
Rows fetched = 0
Buffer pool data logical reads = Not Collected
Buffer pool data physical reads = Not Collected
Buffer pool temporary data logical reads = Not Collected
Buffer pool temporary data physical reads = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool index logical reads = Not Collected
Buffer pool temporary index logical reads = Not Collected
Buffer pool temporary index physical reads = Not Collected
Buffer pool xda logical reads = Not Collected
Buffer pool xda physical reads = Not Collected
Buffer pool temporary xda logical reads = Not Collected
Buffer pool temporary xda physical reads = Not Collected
Blocking cursor = NO
Dynamic SQL statement text:
insert into t3 select * from t3 -- there it is
Agent process/thread ID = 19
Memory usage for application:
Memory Pool Type = Application Heap
Current size (bytes) = 65536
High water mark (bytes) = 65536
Configured size (bytes) = 1048576
Agent process/thread ID = 19
Agent Lock timeout (seconds) = -1
Memory usage for agent:
Memory Pool Type = Other Memory
Current size (bytes) = 524288
High water mark (bytes) = 589824
Configured size (bytes) = 1051570176
[db2inst1@bbbbbb ~]$
------ 转载请标明出处
阅读(5174) | 评论(0) | 转发(0) |