一.安裝過程以下:進入postgreSQL安裝包的contrib/pg_stat_statements目錄,執行編譯和安裝動做:用root用戶sql
make && make installpost
二.安裝成功後,在data/postgresql.conf中,進行配置:postgresql
shared_preload_libraries = 'pg_stat_statements' it
pg_stat_statements.max = 1000io
pg_stat_statements.track = all編譯
三.從新啓動 postgresql,建立sql語句:class
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_statementsselect
order by average desc limit 10;
五.統計結果一直都在,重啓也不會清零,那麼統計結果如何清零從新統計呢?執行下面SQL便可:
select pg_stat_statements_reset() ;