Turn on pg_stat_statements before you need it
The first question in every database incident is "which query", and pg_stat_statements is the only thing that can answer it from history, not just from the moment you happened to look.
SELECT calls, mean_exec_time, query
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10;It costs a few percent. An afternoon spent without it costs more.
postgresqlobservability