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.
postgresql.conf file for your server
shared_preload_libraries = 'pg_stat_statements, pg_stat_plans'pg_stat_plans.compress = 'zstd' or set more configuration parametersCREATE EXTENSION pg_stat_plans;Done! You can now query the pg_stat_plans and pg_stat_activity views.