pg_stat_statements

While in many cases you might still want to save full logs, the pg_stat_statements feature added in PostgreSQL 8.4 can substitute as a way to analyze queries without needing an intermediate logging facility. The feature is documented at http://www.postgresql.org/docs/current/static/pgstatstatements.html.

This is a contrib module, not necessarily installed by default. See the discussion of contrib modules in Chapter 1, PostgreSQL Versions. Like pg_buffercache, it needs to be installed in each database you use it against. Here's an example of installing it on a system with the RedHat Linux directory layout for PostgreSQL:

$ psql -d pgbench -f /usr/share/postgresql/contrib/contrib/pg_stat_statements.sql

You enable this using ...

Get PostgreSQL 10 High Performance 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.