When a query prolongs its execution time, it can significantly affect both the database and the overall system performance such as 1) Increased resource consumption 2) Reduced responsiveness 3) Lock contention 4) Increased disk space usage etc.
The following query lists the longest actively running queries. To gather more information about a specific query which is taking a longer time to execute, use EXPLAIN ANALYZE mentioned in step 5
The following query lists the longest actively running queries. To gather more information about a specific query which is taking a longer time to execute, use EXPLAIN ANALYZE mentioned in step 5
SELECT now() - pg_stat_activity.query_start AS duration, usename, pid, state, query FROM pg_stat_activity WHERE state != 'idle' ORDER BY 1 DESC;