当前位置:网站首页>DB2查看执行过长的SQL
DB2查看执行过长的SQL
2022-08-04 10:47:00 【51CTO】
朋友遇到一个DB2问题,DB2占用了大量的临时表空间,db2pd -d testdb -act发现有大量的SQL长时间运行,为了测试该问题,写了一个简单的处理问题的流程。
1.创建测试表
CREATE TABLE
FUND_DAILY_INCOME
(
ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY,
ACCOUNT_NO VARCHAR(32),
CREATED_TIME TIMESTAMP,
FUND_CODE VARCHAR(8),
SHARE_HOLDING VARCHAR(15),
INCOME_DATE VARCHAR(10),
INCOME_AMOUNT BIGINT,
MERGE_FLAG VARCHAR(1),
OFFSET_FLAG VARCHAR(1),
UPDATE_TIME TIMESTAMP,
COMPANY_CODE VARCHAR(16),
ALL_INCOME DECIMAL(19,0) DEFAULT 0,
HOLDING_INCOME DECIMAL(19,0) DEFAULT 0,
PLAT_ID BIGINT DEFAULT 10000,
SERVICE_TYPE VARCHAR(2) DEFAULT '01',
SERVICE_CODE VARCHAR(32) DEFAULT '10000',
PRIMARY KEY (ID)
);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
2.创建测试存储过程
[[email protected] ~]$ db2 [email protected] -vf 1.sql
[[email protected] ~]$ cat 1.sql
BEGIN
DECLARE v_date date;
DECLARE v_date_str varchar(20);
DECLARE str varchar(20);
DECLARE i INTEGER;
DECLARE val INTEGER;
declare sqlStr varchar(1000);
set v_date = to_date( '2014-01-01' ,'yyyy-mm-dd');
set v_date_str = to_char( v_date ,'yyyy-mm-dd') ;
REPEAT
set i = 1 ;
REPEAT
SET sqlStr =' INSERT INTO FUND_DAILY_INCOME ( ACCOUNT_NO, CREATED_TIME, FUND_CODE, SHARE_HOLDING, INCOME_DATE, INCOME_AMOUNT, MERGE_FLAG, OFFSET_FLAG, UPDATE_TIME, COMPANY_CODE ) VALUES '
|| ' ( ''1'', current timestamp , ''1'', ''1'', '''|| v_date_str ||''' , 0, ''1'', ''1'', current timestamp , ''1'' ) ';
EXECUTE IMMEDIATE sqlStr;
set i = i +1;
UNTIL ( i > 1010000000)
END REPEAT;
set v_date = v_date +1 day;
set v_date_str = to_char( v_date ,'yyyy-mm-dd');
set str = to_char( v_date ,'yyyymmdd');
set val = integer(str);
UNTIL ( val > 20150101)
END REPEAT;
END
@
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
3.查看正在执行的SQL
[[email protected] ~]$ db2pd -d testdb -act
Database Member 0 -- Database TESTDB -- Active -- Up 0 days 00:34:45 -- Date 2021-10-12-16.32.27.821453
Active Statement List:
Address AppHandl [nod-index] UOW-ID StmtID AnchID StmtUID EffISO EffLockTOut EffDegree EntryTime StartTime LastRefTime
0x00007FCBE1F7BC20 7 [000-00007] 58 90956 573 2 1 -1 1 Tue Oct 12 16:32:27 Tue Oct 12 16:32:27 Tue Oct 12 16:32:27
0x00007FCBE1F7F6C0 7 [000-00007] 58 1 931 1 1 -1 1 Tue Oct 12 16:32:20 Tue Oct 12 16:32:20 Tue Oct 12 16:32:20
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
4.查看agentid为7的SQL
[[email protected] ~]$ db2 get snapshot for application agentid 7
Application Snapshot
Application handle = 7
Application status = UOW Waiting
Status change time = Not Collected
Application code page = 1208
Application country/region code = 1
DUOW correlation token = *LOCAL.db2inst1.211012075742
Application name = db2bp
Application ID = *LOCAL.db2inst1.211012075742
Sequence number = 00059
TP Monitor client user ID =
TP Monitor client workstation name =
TP Monitor client application name = CLP 1.sql
TP Monitor client accounting string =
Connection request start timestamp = 10/12/2021 15:57:42.602917
Connect request completion timestamp = 10/12/2021 15:57:43.809901
Application idle time = Not Collected
CONNECT Authorization ID = DB2INST1
Client login ID = db2inst1
Configuration NNAME of client = node02
Client database manager product ID = SQL11014
Process ID of client application = 4224
Platform of client application = LINUXAMD64
Communication protocol of client = Local Client
Inbound communication address = *LOCAL.db2inst1
Database name = TESTDB
Database path = /db2data/db2inst1/NODE0000/SQL00001/MEMBER0000/
Client database alias = TESTDB
Input database alias =
Last reset timestamp =
Snapshot timestamp = 10/12/2021 16:32:44.043410
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
Coordinator member number = 0
Current member number = 0
Coordinator agent process or thread ID = 23
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 = 0
Lock waits since connect = 0
Time application waited on locks (ms) = Not Collected
Deadlocks detected = Not Collected
Lock escalations = 0
Exclusive lock escalations = 0
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 = 0
Commit statements = 3
Rollback statements = 55
Dynamic SQL statements attempted = 236518
Static SQL statements attempted = 58
Failed statement operations = 56
Select SQL statements executed = 1
Xquery statements executed = 0
Update/Insert/Delete statements executed = 236460
DDL statements executed = 1
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 = 236459
Rows updated = 0
Rows selected = 1
Rows read = 12537
Rows written = 236466
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 = 1
Open local cursors = 0
Open local cursors with blocking = 0
Total User CPU Time used by agent (s) = 4.522643
Total System CPU Time used by agent (s) = 0.000000
Host execution elapsed time = Not Collected
Package cache lookups = 236521
Package cache inserts = 374
Application section lookups = 474448
Application section inserts = 371
Catalog cache lookups = 3363
Catalog cache inserts = 42
Catalog cache overflows = 0
Catalog cache high water mark = 0
Workspace Information
Most recent operation = Static Rollback
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) = 262144
High water mark (bytes) = 262144
Configured size (bytes) = 1048576
Agent process/thread ID = 23
Agent Lock timeout (seconds) = -1
Memory usage for agent:
Memory Pool Type = Other Memory
Current size (bytes) = 327680
High water mark (bytes) = 655360
Configured size (bytes) = 16656289792
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
6.收集快照
[[email protected] ~]$ db2 get snapshot for all on testdb > /tmp/1.out
查看里面的内容
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.211012084818
Application name = db2bp
Application ID = *LOCAL.db2inst1.211012084818
Sequence number = 00002
TP Monitor client user ID =
TP Monitor client workstation name =
TP Monitor client application name = CLP 1.sql
TP Monitor client accounting string =
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
7.force掉该agentid
[[email protected] ~]$ db2 "force application (7)"
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
[[email protected] ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
版权声明:本文为博主原创文章,未经博主允许不得转载。
DB2
边栏推荐
猜你喜欢
随机推荐
Mysql 存储引擎简介
ORB-SLAM3中的优化
广东对小鹏/广汽丰田开展网络安全检查
What is the principle of thermal imaging temperature measurement?Do you know?
HTB-Sense
Graphical Hands-on Tutorial--ESP32 One-Key Network Configuration (Smartconfig, Airkiss)
JUC (1) threads and processes, concurrency and parallelism, thread state, locks, producers and consumers
什么是终端特权管理
XCTF-reverse-signin
Jina 实例秀|七夕神器!比你更懂你女友的AI口红推荐
如何直击固定资产管理的难题?
深度学习100例 —— 卷积神经网络(CNN)天气识别
[easyUI]修改datagrid表格中的值
cubemx stm32 afm3000模块 气体流量传感器 驱动代码
8月活动|51CTO十七周年庆,发博文得茶具/笔记本/T恤等礼品!
华为开源:聚焦开源基础软件,共建健康繁荣生态
[论文翻译] Unpaired Image-to-Image Translation using Adversarial Consistency Loss
Heap Sort
iMeta | German National Cancer Center Gu Zuguang published a complex heatmap visualization method
MySQL:面试问的范式设计