RE: psql help

From: Murthy Nunna <mnunna(at)fnal(dot)gov>
To: "depesz(at)depesz(dot)com" <depesz(at)depesz(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: RE: psql help
Date: 2024-07-05 12:37:11
Message-ID: DM8PR09MB667779C739E4F928E7A179A6B8DF2@DM8PR09MB6677.namprd09.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----Original Message-----
From: depesz(at)depesz(dot)com <depesz(at)depesz(dot)com>
Sent: Friday, July 5, 2024 6:05 AM
To: Murthy Nunna <mnunna(at)fnal(dot)gov>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: psql help

[EXTERNAL] – This message is from an external sender

On Fri, Jul 05, 2024 at 03:54:56AM +0000, Murthy Nunna wrote:

> Sorry, there is no problem with the following statement and the environment variable. It works fine. But it terminates only one PID due to LIMIT 1. I want to terminate all pids that meet this criteria. If I remove LIMIT 1, pg_terminate_backend(pid) will not work as it expects only one pid at a time. So, the question is how to rewrite this psql so it loops through all pids one pid at a time? Thanks in advance for your help.

>

> 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;

Did you try?

I don't see any reason why it wouldn't work with just 'limit 1' removed.

Best regards,

depesz

Thanks, depesz. I am pretty sure removing “limit 1” should terminate all pids in the result set. I was just being dumb.

In response to

  • Re: psql help at 2024-07-05 11:05:24 from hubert depesz lubaczewski

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2024-07-05 13:03:15 Re: Load a csv or a avro?
Previous Message hubert depesz lubaczewski 2024-07-05 11:05:24 Re: psql help