How to do it...

Begin by installing the pg_stat_statements module. Follow these steps:

  1. Modify the shared_preload_libraries line in postgresql.conf to include the module:
        shared_preload_libraries = 'pg_stat_statements' 
  1. If you are using PostgreSQL 9.1 or older, add this line to postgresql.conf:
        custom_variable_classes = 'pg_stat_statements' 
  1. Restart PostgreSQL with a command similar to this:
        pg_ctl -D /db/pgdata restart
  1. Log in to PostgreSQL as a superuser into any database that should have access to pg_stat_statements and execute the following SQL statement:
        CREATE EXTENSION pg_stat_statements; 

Perform the following steps to prepare pg_stat_statements for generalized use:

  1. Execute this SQL statement as a database superuser to ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.