假设你在知道application ID的情况下,可以查看sysibmadm.snapstmt视图找到当前执行的SQL语句:db2 update db cfg using CUR_COMMIT OFF;db2 terminatedb2 connect to sampledb2 +c "select * from staff"db2 list application:Auth Id Application &nbs...
显示全部假设你在知道application ID的情况下,可以查看sysibmadm.snapstmt视图找到当前执行的SQL语句:
db2 update db cfg using CUR_COMMIT OFF;
db2 terminate
db2 connect to sample
db2 +c "select * from staff"
db2 list application:
Auth Id Application Appl. Application Id DB # of
Name Handle Name Agents
-------- -------------- ---------- -------------------------------------------------------------- -------- -----
DB2INST1 db2bp 52 *LOCAL.db2inst1.140512112630 SAMPLE 1
DB2INST1 db2bp 33 *LOCAL.db2inst1.140512112429 SAMPLE 1
我是使用52来查询的.
[db2inst1@~]$db2 "select agent_id, substr(stmt_text,1,40) from sysibmadm.snapstmt where agent_id =52"
AGENT_ID 2
-------------------- ----------------------------------------
52 select * from staff
1 record(s) selected.
假设在不知道application ID但是知道SQL的话:
[db2inst1@~]$db2 "select agent_id from sysibmadm.snapstmt where stmt_text like 'select * from staff'
"
AGENT_ID
--------------------
52
1 record(s) selected.
因为这个是动态视图,所以最好是开独自的窗口去监控.如果只用当前会话来查询的话会返回你最后一条执行的SQL语句
收起