在很多客户现场都会遇到数据库执行慢或者其他性能问题,无法定位具体明确是数据库软件问题的时候,GDB工具能帮助我们进一步延伸问题的追踪,继续跟踪到主机、网络和存储等方面数据。
下面是利用GDB工具从数据库会话线程跟踪到对应主机的信息
1. 查找apphandl 30 [db2inst2@db2lab ~]$ db2 list application
Auth Id Application Appl. Application Id DB # of Name Handle Name Agents -------- -------------- ---------- -------------------------------------------------------------- -------- ----- DB2INST2 db2bp 30 *LOCAL.db2inst2.160316172600 SAMPLE 1
2. 查看apphandl 30对应的edu , edu 18 [db2inst2@db2lab ~]$ db2pd -d sample -apinfo 30Database Member 0 -- Database SAMPLE -- Active -- Up 0 days 00:49:44 -- Date 2016-03-17-02.15.44.646551snapapp Time: 03/17/2016 02:15:44Application : Address : 0x0000000203A30080 AppHandl [nod-index] : 30 [000-00030] TranHdl : 3 Application PID : 5722 Application Node Name : db2lab IP Address: n/a Connection Start Time : (1458149160)Thu Mar 17 01:26:00 2016 Client User ID : db2inst2 System Auth ID : DB2INST2 Coordinator EDU ID : 18 Coordinator Member : 0 Number of Agents : 1 Locks timeout value : NotSet Locks Escalation : No Workload ID : 1 Workload Occurrence ID : 1 Trusted Context : n/a Connection Trust Type : non trusted Role Inherited : n/a Application Status : UOW-Waiting Application Name : db2bp Application ID : *LOCAL.db2inst2.160316172600 ClientUserID : n/a ClientWrkstnName : n/a ClientApplName : n/a ClientAccntng : n/a CollectActData: N CollectActPartition: C SectionActuals: N UOW start time : UOW stop time : 03/17/2016 02:14:54.912178 Last executed statements : Package cache ID : 0x0000005100000001 Anchor ID : 81 Statement UID : 1 SQL Type : Dynamic Statement Type : DML, Insert/Update/Delete Statement : insert into t1 select * from t1--------------------------------------------------------------------------------
3.查找edu对应的thread 2722
[db2inst2@db2lab ~]$ db2pd -edusDatabase Member 0 -- Active -- Up 0 days 01:31:55 -- Date 2016-03-17-02.16.19.966832List of all EDUs for database member 0db2sysc PID: 2300 db2wdog PID: 2298 db2acd PID: 2314EDU ID TID Kernel TID EDU Name USR (s) SYS (s) ======================================================================================================================================== 51 140608702244608 6026 db2agntdp (SAMPLE ) 0 0.150000 0.060000 50 140608698050304 6025 db2agent (instance) 0 0.120000 0.140000 49 140608710633216 5735 db2evmgi (DB2DETAILDEADLOCK) 0 0.000000 0.010000 48 140608723216128 5734 db2pcsd (SAMPLE) 0 0.430000 0.340000 47 140608719021824 5733 db2fw0 (SAMPLE) 0 0.010000 0.000000 46 140608706438912 5732 db2lused (SAMPLE) 0 0.420000 0.450000 45 140608727410432 5731 db2wlmd (SAMPLE) 0 0.000000 0.000000 44 140608731604736 5730 db2pfchr (SAMPLE) 0 0.000000 0.000000 43 140608735799040 5729 db2pfchr (SAMPLE) 0 0.000000 0.060000 42 140608714827520 5728 db2pfchr (SAMPLE) 0 0.020000 0.380000 41 140608739993344 5727 db2pclnr (SAMPLE) 0 0.150000 0.530000 40 140608748381952 5726 db2lfr.0 (SAMPLE) 0 0.000000 0.000000 39 140608744187648 5725 db2loggw (SAMPLE) 0 0.140000 4.460000 38 140608752576256 5724 db2loggr (SAMPLE) 0 0.070000 1.390000 37 140608756770560 5723 db2dlock (SAMPLE) 0 0.040000 0.000000 36 140608685467392 5603 db2stmm (SAMPLE) 0 0.530000 0.440000 35 140608689661696 5599 db2taskd (SAMPLE) 0 0.650000 0.380000 34 140608693856000 5332 db2agent (instance) 0 0.040000 0.030000 18 140608760964864 2722 db2agent (SAMPLE) 0 4.190000 10.430000 17 140608765159168 2312 db2resync 0 0.000000 0.000000 16 140608769353472 2311 db2ipccm 0 3.470000 0.730000 15 140608773547776 2309 db2wlmtm 0 1.310000 0.550000 14 140608777742080 2308 db2wlmt 0 0.350000 0.170000 13 140608781936384 2307 db2licc 0 0.000000 0.000000 12 140608786130688 2306 db2thcln 0 0.000000 0.000000 11 140608790324992 2305 db2alarm 0 1.600000 1.080000 1 140608530278144 2304 db2sysc 0 1.510000 3.480000
4. 跟踪db2进程db2sys,查看对应的线程号 2722 [db2inst2@db2lab ~]$ gdb -p 2300 GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Attaching to process 2300(gdb)
(gdb) info thread 28 Thread 0x7fe1f97fe700 (LWP 2304) 0x00000034f6ceae93 in msgrcv () from /lib64/libc.so.6 27 Thread 0x7fe208ffe700 (LWP 2305) 0x00000034f700ed2d in nanosleep () from /lib64/libpthread.so.0 26 Thread 0x7fe208bfe700 (LWP 2306) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 25 Thread 0x7fe2087fe700 (LWP 2307) 0x00000034f700ed2d in nanosleep () from /lib64/libpthread.so.0 24 Thread 0x7fe2083fe700 (LWP 2308) 0x00000034f700ed2d in nanosleep () from /lib64/libpthread.so.0 23 Thread 0x7fe207ffe700 (LWP 2309) 0x00000034f700ed2d in nanosleep () from /lib64/libpthread.so.0 22 Thread 0x7fe207bfe700 (LWP 2311) 0x00000034f6ceae93 in msgrcv () from /lib64/libc.so.6 21 Thread 0x7fe2077fe700 (LWP 2312) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 * 20 Thread 0x7fe2073fe700 (LWP 2722) 0x00000034f6ceaf37 in semop () from /lib64/libc.so.6 19 Thread 0x7fe2033fe700 (LWP 5332) 0x00000034f6ceaf37 in semop () from /lib64/libc.so.6 18 Thread 0x7fe202ffe700 (LWP 5599) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 17 Thread 0x7fe202bfe700 (LWP 5603) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 16 Thread 0x7fe206ffe700 (LWP 5723) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 15 Thread 0x7fe206bfe700 (LWP 5724) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 14 Thread 0x7fe2063fe700 (LWP 5725) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 13 Thread 0x7fe2067fe700 (LWP 5726) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 12 Thread 0x7fe205ffe700 (LWP 5727) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 11 Thread 0x7fe2047fe700 (LWP 5728) 0x00000034f6ceae93 in msgrcv () from /lib64/libc.so.6 10 Thread 0x7fe205bfe700 (LWP 5729) 0x00000034f6ceae93 in msgrcv () from /lib64/libc.so.6 9 Thread 0x7fe2057fe700 (LWP 5730) 0x00000034f6ceae93 in msgrcv () from /lib64/libc.so.6 8 Thread 0x7fe2053fe700 (LWP 5731) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 7 Thread 0x7fe203ffe700 (LWP 5732) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 6 Thread 0x7fe204bfe700 (LWP 5733) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 5 Thread 0x7fe204ffe700 (LWP 5734) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 4 Thread 0x7fe2043fe700 (LWP 5735) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 3 Thread 0x7fe2037fe700 (LWP 6025) 0x00000034f6ceaf37 in semop () from /lib64/libc.so.6 2 Thread 0x7fe203bfe700 (LWP 6026) 0x00000034f6ceafca in semtimedop () from /lib64/libc.so.6 1 Thread 0x7fe2092a0720 (LWP 2300) 0x00000034f70080ad in pthread_join () from /lib64/libpthread.so.0 5. 跟踪线程20 (gdb) thread 20 [Switching to thread 20 (Thread 0x7fe2073fe700 (LWP 2722))]#0 0x00000034f6ceaf37 in semop () from /lib64/libc.so.6
6.打印堆栈
(gdb) bt
#0 0x00000034f6ceaf37 in semop () from /lib64/libc.so.6
#1 0x00007fe21924308d in sqloSSemP () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#2 0x00007fe219174404 in sqlccipcrecv(SQLCC_COMHANDLE_T*, SQLCC_COND_T*) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#3 0x00007fe21917659e in sqlccrecv () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#4 0x00007fe2191b5949 in sqljcReceive(sqljCmnMgr*) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#5 0x00007fe2153da2e7 in sqljsSqlam(db2UCinterface*, sqeAgent*, bool) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#6 0x00007fe2153d8009 in sqljsDriveRequests(sqeAgent*, db2UCconHandle*) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#7 0x00007fe2153d50c9 in sqljsDrdaAsInnerDriver(SQLCC_INITSTRUCT_T*, bool) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#8 0x00007fe2153d4cbb in sqljsDrdaAsDriver(SQLCC_INITSTRUCT_T*) () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#9 0x00007fe2150fded1 in sqeAgent::RunEDU() () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#10 0x00007fe21665d344 in sqzEDUObj::EDUDriver() () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#11 0x00007fe215eb8d05 in sqloEDUEntry () from /home/db2inst2/sqllib/lib64/libdb2e.so.1
#12 0x00000034f7007851 in start_thread () from /lib64/libpthread.so.0
#13 0x00000034f6ce890d in clone () from /lib64/libc.so.6
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞1
添加新评论1 条评论
2016-05-12 15:48