patternsqlMinor
PostgreSQL: Run EXPLAIN on all queries in pg_stat_activity
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:
This query returns the longest-running queries on the database. Then, I manually copy the query text to another window, and run
Is there a way to automatically run
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.