Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Forked from troyk/pg_stat_statements
Created February 28, 2017 14:35
Show Gist options
  • Save nordringrayhide/7b029cd2b595870aa6ec1a0037c9cb2f to your computer and use it in GitHub Desktop.
Save nordringrayhide/7b029cd2b595870aa6ec1a0037c9cb2f to your computer and use it in GitHub Desktop.

Revisions

  1. @troyk troyk created this gist Jan 5, 2013.
    14 changes: 14 additions & 0 deletions pg_stat_statements
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020

    2) add to postgresql.conf:
    shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
    136 pg_stat_statements.max = 1000
    137 pg_stat_statements.track = all

    3) restart postgres

    4) check it out in psql
    psql: CREATE EXTENSION pg_stat_statements;
    psql: \x
    psql: SELECT query, calls, total_time, rows, 100.0 * shared_blks_hit / nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent FROM pg_stat_statements ORDER BY total_time DESC LIMIT 5;