Check out our new Resources section: Read through our eBooks and learn how customers are using pganalyze. See all resources

Step 2: Enable pg_stat_statements

Enable pg_stat_statements in your Postgres container configuration

To get query statistics in Postgres, we need to modify the Postgres config setting called shared_preload_libraries.

You can do this by stopping your Postgres container, and then starting it again with the correct configuration as part of the command line arguments:

docker run -d --name my-pg postgres -c "shared_preload_libraries='pg_stat_statements'"

Verify that pg_stat_statements returns data

As a superuser, run the following statements:

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT calls, query FROM pg_stat_statements LIMIT 1;

If you have configured your database correctly, this will return a result like this:

 calls | query
-------+-------
     8 | SELECT * FROM t WHERE field = ?
(1 row)

If you get an error you might not have restarted the container, or passed the configuration settings the right way. If you get stuck feel free to reach out to us, we're happy to help.

Next we continue by installing the pganalyze collector:

Proceed to Step 3: Install the collector

Couldn't find what you were looking for or want to talk about something specific?
Start a conversation with us →