Analysing/Profiling queries on PostgreSQL

Andy.l picture Andy.l · Mar 5, 2015 · Viewed 8.2k times · Source

I've just inherited an old PostgreSQL installation and need to do some diagnostics to find out why this database is running slow. On MS SQL you would use a tool such as Profiler to see what queries are running and then see how their execution plan looks like.

What tools, if any, exist for PostgreSQL that I can do this with? I would appreciate any help since I´m quite new with Postgres.

Answer

Vao Tsun picture Vao Tsun · Mar 11, 2015

Use pg_stat_statements extension to get long running queries. then use select* from pg_stat_statements order by total_time/calls desc limit 10 to get ten longest. then use explain to see the plan...