Postgres.app

The easiest way to get started with PostgreSQL on the Mac

Using pg_stat_plans with Postgres.app

The pg_stat_plans extension allows to track per-plan call counts, execution times and EXPLAIN texts PostgreSQL.

Similar to what pg_stat_statements provides for query planning and execution, pg_stat_plans tracks statistics on execution plans. In contrast to auto_explain the collected data is cumulative and can be queried from SQL. Additionally, you can retrieve the plan of currently running queries.

We are offering pg_stat_plans as an additional download for Postgres.app. Usually, this is used in combination with the bundled contrib extension pg_stat_statements. You can join both statistics on the queryid column. When loaded, pg_plan_advice strings can be collected in addition to the plan texts.

Installing pg_stat_plans for Postgres.app

  1. Download the pg_stat_plans installer package from https://postgresapp.com/extensions/
  2. Double click the package and go through all steps to install the extension
  3. Find the postgresql.conf file for your server
    • open Postgres.app
    • click the “Server Settings…” button
    • find the “Config” file path and click “Show”
    • open the config file with your favorite text editor
  4. Update configuration parameters:
    • add pg_stat_plans coma separated to shared preload libraries, eg. shared_preload_libraries = 'pg_stat_statements, pg_stat_plans'
    • optionally, enable zstd compression for plan texts by adding pg_stat_plans.compress = 'zstd' or set more configuration parameters
  5. Restart the PostgreSQL server
  6. Connect to the database you want to use pg_stat_plans
  7. Activate the extension: CREATE EXTENSION pg_stat_plans;

Done! You can now query the pg_stat_plans and pg_stat_activity views.