Postgresql监控Top SQL

参考:

https://github.com/digoal/blog/blob/master/201704/20170424_06.md

PG 库优化路漫漫,如果没有合适的工具 、规范或者方法提前发现数据库性能问题,只能通过应用倒逼发现数据库问题,非常被动。

变被动为主动的前提是手持利器 。

• create extension pg_stat_statements;
最耗时 SQL (整体数据库优化,建议以此结果逐条优化,效果立竿见影)
• 总最耗时 SQL TOP 5
select dbid, query from pg_stat_statements order by total_time desc limit 5;
• 其他
最耗IO SQL
• 总最耗IO SQL TOP 5
select dbid, query from pg_stat_statements order by (blk_read_time+blk_write_time) desc limit 5;
响应时间抖动最严重 SQL
select dbid, query from pg_stat_statements order by stddev_time desc limit 5;
最耗共享内存 SQL
select dbid, query from pg_stat_statements order by (shared_blks_hit+shared_blks_dirtied) desc limit 5;
最耗临时空间 SQL
select dbid, query from pg_stat_statements order by temp_blks_written desc limit 5;
 

你可能感兴趣的:(PostgreSQL)