【PostgreSQL查看SQL执行过程主机的资源使用情况】

在分析SQL的时候,可以临时设置client_min_messages=log结合如下几个参数分别查看SQL在explain, parser, execute 过程系统资源使用分析。

生产环境不建议开启,建议临时分析会话级别开启,用于定位问题。

postgres=# select name from pg_settings where name like '%stats';
        name
---------------------
 log_executor_stats
 log_parser_stats
 log_planner_stats
 log_statement_stats
(4 rows)

一、log_executor_stats 查看执行过程资源使用

postgres=# set client_min_messages =log;
SET
postgres=# set log_executor_stats=on;
SET
postgres=# select 1;
LOG:  EXECUTOR STATISTICS
DETAIL:  ! system usage stats:
!       0.000000 s user, 0.000011 s system, 0.000010 s elapsed
!       [0.000000 s user, 0.002140 s system total]
!       4216 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/2 [0/915] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [4/0] voluntary/involuntary context switches
 ?column?
----------
        1
(1 row)

二、log_parser_stats 查看解析过程资源使用

postgres=# set client_min_messages =log;
SET
postgres=# set log_parser_stats=on;
SET
postgres=# select 1;
LOG:  PARSER STATISTICS
DETAIL:  ! system usage stats:
!       0.000017 s user, 0.000017 s system, 0.000032 s elapsed
!       [0.000934 s user, 0.000934 s system total]
!       3692 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/17 [0/819] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [3/0] voluntary/involuntary context switches
LOG:  PARSE ANALYSIS STATISTICS
DETAIL:  ! system usage stats:
!       0.000013 s user, 0.000013 s system, 0.000026 s elapsed
!       [0.000983 s user, 0.000983 s system total]
!       3948 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/19 [0/854] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [3/0] voluntary/involuntary context switches
LOG:  REWRITER STATISTICS
DETAIL:  ! system usage stats:
!       0.000003 s user, 0.000003 s system, 0.000005 s elapsed
!       [0.000994 s user, 0.000994 s system total]
!       3948 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/4 [0/858] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [3/0] voluntary/involuntary context switches
 ?column?
----------
        1
(1 row)

三、log_planner_stats查看PLANNER过程资源使用

postgres=# set client_min_messages =log;
SET
postgres=# set log_planner_stats=on;
SET
postgres=# select 1;
LOG:  PLANNER STATISTICS
DETAIL:  ! system usage stats:
!       0.000000 s user, 0.000098 s system, 0.000097 s elapsed
!       [0.000000 s user, 0.002105 s system total]
!       3952 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/53 [0/895] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [3/0] voluntary/involuntary context switches
 ?column?
----------
        1
(1 row)

四、log_statement_stats

postgres=# set client_min_messages =log;
SET
postgres=# set log_statement_stats=on;
SET
postgres=# select 1;
LOG:  QUERY STATISTICS
DETAIL:  ! system usage stats:
!       0.000000 s user, 0.000249 s system, 0.000250 s elapsed
!       [0.000000 s user, 0.002201 s system total]
!       4216 kB max resident size
!       0/0 [0/0] filesystem blocks in/out
!       0/114 [0/916] page faults/reclaims, 0 [0] swaps
!       0 [0] signals rcvd, 0/0 [0/0] messages rcvd/sent
!       0/0 [3/0] voluntary/involuntary context switches
 ?column?
----------
        1
(1 row)
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小怪兽ysl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值