postgres定位执行慢的SQL的方法
来源:互联网 发布:算法研究员是做什么 编辑:程序博客网 时间:2024/06/05 03:14
定位慢查询SQL
可以设置一定时长的参数(log_min_duration_statement),来记录超过该时长的所有SQL,对找出当前数据库的慢查询很有效。 比如log_min_duration_statement = 2s,记录超过2秒的SQL,改完需要reload
示例:
postgres=# show log_min_duration_statement ;
log_min_duration_statement
----------------------------
2s
(1 row)
postgres=# \timing
Timing is on.
postgres=# select now(),pg_sleep(1);
now | pg_sleep
------------------------------+----------
2013-03-29 12:36:48.13353-07 |
(1 row)
Time: 1001.844 ms
postgres=# select now(),pg_sleep(4);
now | pg_sleep
-------------------------------+----------
2013-03-29 12:36:28.309595-07 |
(1 row)
Time: 4002.273 ms
[postgres@localhost pg_log]$ tail -f postgresql-2013-03-29_000000.csv
2013-03-29 12:36:19.265 PDT,"postgres","postgres",2324,"[local]",5155d681.914,10,"SELECT",2013-03-29 10:59:29 PDT,2/0,0,LOG,00000,"duration: 4027.183 ms statement: select now(),pg_sleep(4);",,,,,,,,,"psql"
可以看到只记录了4秒的那个SQL,而没有记录1秒的SQL。
可以设置一定时长的参数(log_min_duration_statement),来记录超过该时长的所有SQL,对找出当前数据库的慢查询很有效。 比如log_min_duration_statement = 2s,记录超过2秒的SQL,改完需要reload
示例:
postgres=# show log_min_duration_statement ;
log_min_duration_statement
----------------------------
2s
(1 row)
postgres=# \timing
Timing is on.
postgres=# select now(),pg_sleep(1);
now | pg_sleep
------------------------------+----------
2013-03-29 12:36:48.13353-07 |
(1 row)
Time: 1001.844 ms
postgres=# select now(),pg_sleep(4);
now | pg_sleep
-------------------------------+----------
2013-03-29 12:36:28.309595-07 |
(1 row)
Time: 4002.273 ms
[postgres@localhost pg_log]$ tail -f postgresql-2013-03-29_000000.csv
2013-03-29 12:36:19.265 PDT,"postgres","postgres",2324,"[local]",5155d681.914,10,"SELECT",2013-03-29 10:59:29 PDT,2/0,0,LOG,00000,"duration: 4027.183 ms statement: select now(),pg_sleep(4);",,,,,,,,,"psql"
可以看到只记录了4秒的那个SQL,而没有记录1秒的SQL。
阅读全文
0 0
- postgres定位执行慢的SQL的方法
- 通过MySQL慢查询日志定位执行效率低的SQL语句
- 连接postgres的方法
- SQLServer找出执行慢的SQL语句
- JDBC执行sql慢的问题
- SQLServer找出执行慢的SQL语句
- SQLServer找出执行慢的SQL语句
- 如何找出执行最慢的SQL
- SQLServer找出执行慢的SQL语句
- Oracle 查询每天执行慢的SQL
- SQLServer找出执行慢的SQL语句
- 最近执行较慢的SQL
- 优化慢执行或慢查询的方法
- MySQL优化 之 定位慢查询的sql语句
- Tips: 快速查询定位最慢的SQL
- 如何用sql profile 找出执行慢的sql
- postgres数据表行转列的方法
- 如何看懂Postgres的执行计划
- 静态顺序表的C语言实现
- C++传引用
- 实用函数之计算某天是星期几
- DSP芯片CMD文件中各段的实验验证(下)
- Spring整合ActiveMQ
- postgres定位执行慢的SQL的方法
- C#221课的主要内容
- Max Sequence
- 微信公众平台java接入
- java异常拓展
- ubuntu上安装及破解sublime,以及禁止更新
- 小学生算术
- C# string类型和byte[]类型相互转换
- 我的重要网站