HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

PostgreSQL: Run EXPLAIN on all queries in pg_stat_activity

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlqueriesallpg_stat_activityexplainrun

Problem

I am investigating high load on a PostgreSQL database on RDS. As a part of the investigation, I'm running the following query:

SELECT now()-query_start, state, query FROM pg_stat_activity ORDER BY 1 DESC;


This query returns the longest-running queries on the database. Then, I manually copy the query text to another window, and run EXPLAIN on each query to identify longer queries that need indexing.

Is there a way to automatically run EXPLAIN on each query in pg_stat_activity?

Solution

It's not exactly what you are looking for, but the auto_explain extension may be as close as you can get. See auto_explain

Context

StackExchange Database Administrators Q#111160, answer score: 4

Revisions (0)

No revisions yet.