一.安装过程如下:进入postgreSQL安装包的contrib/pg_stat_statements目录,执行编译和安装动作:用root用户
make && make install
二.安装成功后,在data/postgresql.conf中,进行配置:
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = all
三.重新启动 postgresql,创建sql语句:
create extension pg_stat_statements;
四.查询哪些sql语句执行效率慢:
select query ,calls,total_time,(total_time/calls) as average,rows,100.0 * shared_blks_hit /nullif(shared_blks_hit + shared_blks_read,0) as hit_precent
from pg_stat_statements
order by average desc limit 10;
五.统计结果一直都在,重启也不会清零,那么统计结果如何清零重新统计呢?执行下面SQL即可:
select pg_stat_statements_reset() ;