【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 查看执行过程资源使用

language 复制代码
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 查看解析过程资源使用

language 复制代码
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过程资源使用

language 复制代码
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

language 复制代码
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)
相关推荐
Leo.yuan12 分钟前
数据量大Excel卡顿严重?选对报表工具提高10倍效率
数据库·数据分析·数据可视化·powerbi
Runing_WoNiu21 分钟前
MySQL与Oracle对比及区别
数据库·mysql·oracle
天道有情战天下42 分钟前
mysql锁机制详解
数据库·mysql
看山还是山,看水还是。44 分钟前
Redis 配置
运维·数据库·redis·安全·缓存·测试覆盖率
谷新龙0011 小时前
Redis运行时的10大重要指标
数据库·redis·缓存
CodingBrother1 小时前
MySQL 中单列索引与联合索引分析
数据库·mysql
精进攻城狮@1 小时前
Redis缓存雪崩、缓存击穿、缓存穿透
数据库·redis·缓存
小酋仍在学习1 小时前
光驱验证 MD5 校验和
数据库·postgresql
keep__go1 小时前
Linux 批量配置互信
linux·运维·服务器·数据库·shell
小王同学mf1 小时前
怎么尽可能保证 Kafka 的可靠性
数据库