From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
Date: Wed, 8 Dec 2021 01:23:32 -0600
Message-ID: <7ab7add9-9c1b-3842-e4eb-f78107964db3@gmail.com> (raw)
In-Reply-To: <OS3PR01MB581659FF3F8020F174751B4BA76F9@OS3PR01MB5816.jpnprd01.prod.outlook.com>
References: <OS3PR01MB581659FF3F8020F174751B4BA76F9@OS3PR01MB5816.jpnprd01.prod.outlook.com>
On 12/8/21 12:45 AM, Md Arqum Farooqui wrote:
>
> Hi,
>
> I'm facing "Too many clients already" error frequently with my PostgreSQL
> (v9.6.5)
>
You really need to update to 9.6.24.
> container (i.e. being used along with CKAN application i.e. A open source
> data management system <https://ckan.org/> ), I have observed that
> PostgreSQL is not releasing IDLE connections from their end. I have set
> "max_connetions = 100" in postgresql.
>
> Please provide your suggestions on below queries:
>
> 1. Why PostgreSQL is not releasing IDLE connection?
>
It is the application's job to close connections when they are no longer of use.
> (If we leave the setup then postgres keep IDLE connection even for 1
> month, after that I have to restart the Postgres)
> 2. Is there any parameter or any solution by which i can remove unused old
> IDLE connection regularly?
>
I set up a cron job that regularly kills old idle connections.
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'databasename'
AND pid <> pg_backend_pid()
AND state = 'idle'
and extract(epoch from (current_timestamp - query_start)) > 20*60 -- 20
minutes
;
--
Angular momentum makes the world go 'round.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: ronljohnsonjr@gmail.com, pgsql-admin@lists.postgresql.org
Subject: Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
In-Reply-To: <7ab7add9-9c1b-3842-e4eb-f78107964db3@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox