psql help

From: Murthy Nunna <mnunna(at)fnal(dot)gov>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: psql help
Date: 2024-07-04 23:56:03
Message-ID: DM8PR09MB6677C5B4FDBDFC0F82298DC7B8DE2@DM8PR09MB6677.namprd09.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-07-05 01:11:47 Re: JSONPath operator and escaping values in query
Previous Message Guyren Howe 2024-07-04 23:29:13 Re: Design strategy for table with many attributes