psql:定位慢查询
定位psql的慢查询语句:
1.修改/pgsql/data/postgresql.conf中的log_min_duration_statement,单位毫秒。例log_min_duration_statement=5000
2.查看当前设置:show log_min_duration_statement;
===>5s
3.执行一条超出5s的sql。例select now(),pg_sleep(6);
===>该sql会在6s后执行结束
4.查看psql日志,/pg_log/postgresql-2020-10-20_0000.log
===>有一行:“[local]>LOG:duration:xxxms statement:query;”,此条sql即为慢sql,定位到后即对其进行分析调优
附:select pg_reload_conf();实现pgsql的reload
转载:https://blog.csdn.net/ctypyb2002/article/details/83151457