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

news/2024/7/9 22:59:13 标签: 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)

http://www.niftyadmin.cn/n/5304762.html

相关文章

lumina电源维修CCPF-3800/1000-900P-SW Univ Mnt

维修产品有:靶材电源维修;等离子电源维修;镀膜机电源维修;射频电源维修;ICP电源维修;镀膜机控制器维修;RF电源维修;匹配器维修;电源控制器维修;氧化源控制器维…

AE (4)_ 直方图调整的理论

#灵感# 在短暂的高通平台调试中,很看重直方图调整的理解。后来其它平台,不怎么调整这个了。但还是记录一下。 我个人还是倾向 招式简单,但应用到极致。 绝大部分内容来自:刘斯宁,Image Enhancement - CLAHE - 知乎 (z…

JavaScript基本使用方法

JavaScript 是一种脚本语言,常用于 Web 开发。这里是一些基本的使用方法: 声明变量: 在 JavaScript 中,可以使用 var、let 或 const 关键字来声明变量。例如: var age 25; let name "John"; const PI …

掌握 Copilot:AI编程的未来

掌握 Copilot:AI编程的未来 前言: 欢迎来到本篇博客,今天我们将深入介绍一款颠覆性的编程辅助工具——Copilot。作为 GitHub Copilot 插件的使用者,你将体验到人工智能在编程领域的前沿应用,为你的代码编写提供更快、更智能的支…

Java调用百度云语音识别【音频转写】

百度云文档 ttps://ai.baidu.com/ai-doc/SPEECH/Bk5difx01 示例代码: import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import lombok.extern.slf4j.Slf4j; import okhttp3.*; import org.json.JSONObject; import org.springframework.stereoty…

如何通过Python将各种数据写入到Excel工作表

在数据处理和报告生成等工作中,Excel表格是一种常见且广泛使用的工具。然而,手动将大量数据输入到Excel表格中既费时又容易出错。为了提高效率并减少错误,使用Python编程语言来自动化数据写入Excel表格是一个明智的选择。Python作为一种简单易…

Vue2.Hello World

步骤: 准备容器引包(开发版本/生产版本)创建实例new Vue()添加配置项 el指定挂载点data提供数据 准备容器 就是新建一个div标签 引包 vue2版本中文文档:https://v2.cn.vuejs.org/v2/guide/ 尝试 Vue.js 最简单的方法是使用 …

123基于matlab的差分优化算法优化极限学习机,DE-ELM

基于matlab的差分优化算法优化极限学习机,DE-ELM。输出分类识别结果和准确率。数据可更换自己的,程序已调通,可直接运行。 123差分优化算法极限学习机 (xiaohongshu.com)