Re: psql help - Mailing list pgsql-general

From hubert depesz lubaczewski
Subject Re: psql help
Date
Msg-id ZofTdC3Fgc-75tzg@depesz.com
Whole thread Raw
In response to RE: psql help  (Murthy Nunna <mnunna@fnal.gov>)
Responses RE: psql help
List pgsql-general
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
terminatesonly 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
psqlso 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




pgsql-general by date:

Previous
From: Muhammad Ikram
Date:
Subject: Re: Load a csv or a avro?
Next
From: Murthy Nunna
Date:
Subject: RE: psql help