Hello: Following works- SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid IN (select unnest(pg_blocking_pids(pid)) from pg_stat_activity where cardinality(pg_blocking_pids(pid)) > 0) and usename = 'DBUSER_10' and now() - state_change >= interval $a'${TIMEOUT_MINS}'$a order by now() - state_change >= interval $a'${TIMEOUT_MINS}'$a desc limit 1; How can I rewrite the above in psql and pg_terminate_backend all pids that meet above criteria (essentially remove limit 1) ? Thanks! Note: I run this in Linux. TIMEOUT_MINS is env variable. |