Skip to content

Instantly share code, notes, and snippets.

@diegolovison
Last active April 1, 2025 20:01
Show Gist options
  • Save diegolovison/d3b72a331649c27f2fca900f27bc60fa to your computer and use it in GitHub Desktop.
Save diegolovison/d3b72a331649c27f2fca900f27bc60fa to your computer and use it in GitHub Desktop.
Enabling pg_stat_statements

Find the postgresql.conf location

$ psql -U postgres -c 'show config_file'
               config_file               
-----------------------------------------
 /path/to/postgresql.conf

Edit the file content by adding

shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all

Restart the database

sudo systemctl restart postgresql

Execute the following on the database that you wish to track

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

Check by using

SELECT count(*) FROM pg_stat_statements;

Check configuration

psql -U postgres -c 'show max_wal_size'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment