修改postgresql.conf
shared_preload_libraries ,增加pg_stat_statements
加载扩展
create extension pg_stat_statements;
重置计数器
select pg_stat_reset();
select pg_stat_statements_reset();
查询耗时的sql
select * from pg_stat_statements order by total_time desc limit 5;
查询buffer读取次数多的sql
select * from pg_stat_statements order by shared_blks_hit+shared_blks_read desc limit 5;
参考:https://help.aliyun.com/knowledge_detail/43562.html
https://www.cnblogs.com/hellojesson/p/10911034.html