在openGauss/MogDB数据库THREAD_WAIT_STATUS、PG_THREAD_WAIT_STATUS、GLOBAL_THREAD_WAIT_STATUS、LOCAL_ACTIVE_SESSION的几个视图里都有lwtid这一列,他是当前线程的轻量级线程号。可以根据这一列通过pstack命令去抓取堆栈,供问题的分析。
如下所示,可以用pg_stat_activity 和dbe_perf.thread_wait_status结合,查询当前正在运行的一些SQL,通过
MogDB=# select pid,lwtid,state,wait_event,query from pg_stat_activity a,dbe_perf.thread_wait_status s where a.pid=s.tid; pid | lwtid | state | wait_event | query ----------------+---------+--------+------------+------------------------------------------------------------------------------------------------------------- ------ 23043933468416 | 1724740 | active | none | select pid,lwtid,state,wait_event,query from pg_stat_activity a,dbe_perf.thread_wait_status s where a.pid=s .tid; 23044103272192 | 1724300 | active | none | select pg_sleep(30); 23044453037824 | 1526848 | | none | 23044479776512 | 1526847 | | none | 23044508612352 | 1526846 | active | none | WLM fetch collect info from data nodes 23044674287360 | 1526842 | idle | none | 23044771804928 | 1526839 | idle | none | 23044739823360 | 1526840 | active | none | 23044698928896 | 1526841 | active | none | 23044832098048 | 1526837 | | none | 23044928567040 | 1526834 | active | none | (11 rows)
复制
我们通过pstack去查看上边lwtid=1724300 对应的select pg_sleep(30);的堆栈。
[ptk1@mogdb-kernel-0005 ~]$ pstack 1724300 Thread 1 (Thread 0x14f55f96f700 (LWP 1724300)): #0 0x000014f98e8d829f in select () from /lib64/libc.so.6 #1 0x0000555ba97ae25d in pg_usleep(long) () #2 0x0000555ba87cef4a in pg_sleep(FunctionCallInfoData*) () #3 0x0000555ba8fad525 in ?? () #4 0x0000555ba8fadb59 in ExecProject(ProjectionInfo*, ExprDoneCond*) () #5 0x0000555ba8ffb948 in ExecResult(ResultState*) () #6 0x0000555ba8f9c6ee in ExecProcNode(PlanState*) () #7 0x0000555ba8f95318 in standard_ExecutorRun(QueryDesc*, ScanDirection, long) () #8 0x0000555ba8e25ed5 in ?? () #9 0x0000555ba8f956ad in ExecutorRun(QueryDesc*, ScanDirection, long) () #10 0x0000555ba8f148b3 in ?? () #11 0x0000555ba8f14fa0 in PortalRun(PortalData*, long, bool, _DestReceiver*, _DestReceiver*, char*) () #12 0x0000555ba8f095a2 in ?? () #13 0x0000555ba8f0ce97 in PostgresMain(int, char**, char const*, char const*) () #14 0x0000555ba8e6b501 in ?? () #15 0x0000555ba8e89fb8 in int GaussDbThreadMain<(knl_thread_role)1>(knl_thread_arg*) () #16 0x0000555ba8e6b585 in ?? () #17 0x000014f98ebb117a in start_thread () from /lib64/libpthread.so.0 #18 0x000014f98e8e0dc3 in clone () from /lib64/libc.so.6
复制
可以清晰地看到,堆栈从PostgresMain到后来调用了pg_sleep的各个部分,以及后来的pg_usleep休眠部分。
也可以根据lwtid找到想分析的一些关键线程,例如一些特殊功能的线程,如WDRSnapshot、ASP、CheckPointer等、或者是在数据库中有长时间在跑的SQL的线程以及需要分析的等待事件对应的线程。
node_name | db_name | thread_name | query_id | tid | sessionid | lwtid | psessionid | tlevel | smpid | wait_status | wa it_event | locktag | lockmode | block_sessionid | global_sessionid -----------+----------+------------------------+------------------+----------------+----------------+---------+------------+--------+-------+-------------+--- ---------+---------+----------+-----------------+------------------ dn_6001 | postgres | gsql | 1407374883636205 | 23044103272192 | 23044103272192 | 1724935 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | WLMArbiter | 0 | 23044453037824 | 23044453037824 | 1526848 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | WorkloadMonitor | 0 | 23044479776512 | 23044479776512 | 1526847 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | workload | 0 | 23044508612352 | 23044508612352 | 1526846 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | statement flush thread | 0 | 23044674287360 | 23044674287360 | 1526842 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | WDRSnapshot | 1407374883553280 | 23044771804928 | 23044771804928 | 1526839 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | PercentileJob | 0 | 23044739823360 | 23044739823360 | 1526840 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | Asp | 0 | 23044698928896 | 23044698928896 | 1526841 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | ApplyLauncher | 0 | 23044832098048 | 23044832098048 | 1526837 | | 0 | 0 | none | no ne | | | | 0:0#0 dn_6001 | postgres | JobScheduler | 0 | 23044928567040 | 23044928567040 | 1526834 | | 0 | 0 | none | no ne | | | | 0:0#0 (10 rows)
复制
如下所示,可以看到lwtid=1526839对应的是WDRSnapshot线程它当前的一个堆栈情况。
[ptk1@mogdb-kernel-0005 ~]$ pstack 1526839 Thread 1 (Thread 0x14f5876ff700 (LWP 1526839)): #0 0x000014f98e8d829f in select () from /lib64/libc.so.6 #1 0x0000555ba97ae25d in pg_usleep(long) () #2 0x0000555ba8a83e83 in SnapshotNameSpace::SubSnapshotMain() () #3 0x0000555ba8a843c5 in SnapshotMain() () #4 0x0000555ba8e87e41 in int GaussDbThreadMain<(knl_thread_role)35>(knl_thread_arg*) () #5 0x0000555ba8e6b585 in ?? () #6 0x000014f98ebb117a in start_thread () from /lib64/libpthread.so.0 #7 0x000014f98e8e0dc3 in clone () from /lib64/libc.so.6
复制
最后修改时间:2022-07-28 16:54:30
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
文章被以下合辑收录
评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
562次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
309次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
202次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
176次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
165次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
151次阅读
2025-04-30 16:39:58
Postgresql数据库单个Page最多存储多少行数据
maozicb
97次阅读
2025-04-23 16:02:19
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
97次阅读
2025-04-18 10:49:53
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
68次阅读
2025-04-17 10:41:47
RISC-V 首迎 openGauss 7.0.0-RC1 全量版适配!数据库核心功能完整落地开源架构
openGauss
51次阅读
2025-04-16 10:33:59