public inbox for [email protected]  
help / color / mirror / Atom feed
Deleting idle connections
2+ messages / 2 participants
[nested] [flat]

* Deleting idle connections
@ 2025-02-24 22:49 Yongye Serkfem <[email protected]>
  2025-02-24 23:12 ` Re: Deleting idle connections Ron Johnson <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Yongye Serkfem @ 2025-02-24 22:49 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <[email protected]>

Hi Everyone!
I am having a series of idle connections and unable to delete them with a
single command. Any help in realizing this would be greatly appreciated.

Regards
Yong


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Deleting idle connections
  2025-02-24 22:49 Deleting idle connections Yongye Serkfem <[email protected]>
@ 2025-02-24 23:12 ` Ron Johnson <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Ron Johnson @ 2025-02-24 23:12 UTC (permalink / raw)
  To: pgsql-general

On Mon, Feb 24, 2025 at 5:50 PM Yongye Serkfem <[email protected]> wrote:

> Hi Everyone!
> I am having a series of idle connections and unable to delete them with a
> single command. Any help in realizing this would be greatly appreciated.
>

This will kill idle connections older than two hours:
select pid, pg_terminate_backend(pid)
from pg_stat_activity
where state = 'idle'
  and (EXTRACT(epoch FROM now() - backend_start))/3600.0 > 2;

Be warned that it might kill more than you want.  Add more WHERE predicates
as filter.

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-02-24 23:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-24 22:49 Deleting idle connections Yongye Serkfem <[email protected]>
2025-02-24 23:12 ` Ron Johnson <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox