Skip to content

Instantly share code, notes, and snippets.

@evilkost
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilkost/dafde8ea28e1787a297a to your computer and use it in GitHub Desktop.
Save evilkost/dafde8ea28e1787a297a to your computer and use it in GitHub Desktop.

Enable module:

vim /var/lib/pgsql/data/postgresql.conf

add at the end:

shared_preload_libraries = 'pg_stat_statements'
# Increase the max size of the query strings Postgres records
track_activity_query_size = 2048

Restart server:

systemctl restart postgresql

In psql:

CREATE EXTENSION pg_stat_statements;

Change output format:

\x on

Query stats:

select query, total_time, calls, rows from pg_stat_statements() order by total_time desc limit 2;

Disable:

DROP EXTENSION pg_stat_statements;

Reset stats:

SELECT pg_stat_statements_reset();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment