O'Reilly logo

Mastering PostgreSQL 10 by Hans-Jurgen Schonig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using pg_stat_statements

After discussing the first couple of views, it is time to turn our attention to one of the most important views, which can be used to spot performance problems. I am, of course, speaking about pg_stat_statements. The idea is to have information about queries on your system. It helps to figure out which types of queries are slow and how often queries are called.

To use the module, three steps are necessary:

  • Add pg_stat_statements to shared_preload_libraries in the postgresql.conf file
  • Restart the database server
  • Run CREATE EXTENSION pg_stat_statements in the database(s) of your choice

Let's inspect the definition of the view:

test=# \d pg_stat_statements View "public.pg_stat_statements" Column | Type |... ---------------------+------------------+... ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required