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();