Check out our free resources, like our pganalyze eBooks and sign up to our newsletter.

Enabling pg_stat_statements

We use the pg_stat_statements extension (officially bundled with PostgreSQL) for tracking which queries get executed in your database.

The query information collected by the extension is cleaned and then sent to our servers using our collector script.

The extension's normalization code cleans the actual values from the queries,
turning SELECT * FROM t WHERE secret = '123' into SELECT * FROM t WHERE secret = ?.

We still recommend that you use prepared statements if you query for highly sensitive data.

Note: We never collect any stored data, or data returned by queries.

Install official PostgreSQL contrib package

On your database server, make sure that the extensions package is installed.

Debian/Ubuntu:

# Replace 9.X with your installed Postgres version:
sudo apt-get install postgresql-contrib-9.X

RedHat/CentOS/SLES:

sudo yum install postgresql-contrib

Configure PostgreSQL

Add the following entries to your postgres.conf:

shared_preload_libraries = 'pg_stat_statements'

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

# Track statements generated by stored procedures as well
pg_stat_statements.track = all

If you're running PostgreSQL 9.2 you may need to increase your OS shared memory limits when using pg_stat_statements.
See the Postgres shared memory documentation for details on how to do this.

Restart the PostgreSQL daemon

sudo service postgresql restart

(Yeah, we don't like that reboot either, but PostgreSQL requires it for the time being)



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