pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
5+ messages / 5 participants
[nested] [flat]
* PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
@ 2021-12-08 06:45 Md Arqum Farooqui <Md.Farooqui@india.nec.com>
0 siblings, 2 replies; 5+ messages in thread
From: Md Arqum Farooqui @ 2021-12-08 06:45 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Hi,
I'm facing "Too many clients already" error frequently with my PostgreSQL (v9.6.5) 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? (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?
Thanks and Regards,
Arqum farooqui
________________________________
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NEC Corporation India Private Limited or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NEC Corporation India Private Limited or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
@ 2021-12-08 07:23 Ron <ronljohnsonjr@gmail.com>
parent: Md Arqum Farooqui <Md.Farooqui@india.nec.com>
1 sibling, 1 reply; 5+ messages in thread
From: Ron @ 2021-12-08 07:23 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
@ 2021-12-08 09:18 Paul Smith <paul@pscs.co.uk>
parent: Md Arqum Farooqui <Md.Farooqui@india.nec.com>
1 sibling, 1 reply; 5+ messages in thread
From: Paul Smith @ 2021-12-08 09:18 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
On 08/12/2021 06:45, Md Arqum Farooqui wrote:
>
> Hi,
>
> I'm facing "Too many clients already" error frequently with my
> PostgreSQL (v9.6.5) 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.
>
It is the responsibility of the client software to release connections
when they are no longer needed. The server won't just time-out idle
connections unless it is told to do so
I guess CKAN is keeping a pool of available connections that it can
reuse without having to start a new connection. You may be able to set
parameters in CKAN so that it kills connections after they have been
idle a while. If you're not sure, you really need to ask on a CKAN
support forum
Or you could use a separate connection pooler (eg PgBouncer) and have
CKAN connect to that instead of the database directly. The pooler will
then manage reuse across all the client applications, and may be able to
timeout idle connections for you.
--
Paul
Paul Smith Computer Services
support@pscs.co.uk - 01484 855800
--
Paul Smith Computer Services
Tel: 01484 855800
Vat No: GB 685 6987 53
Sign up for news & updates at http://www.pscs.co.uk/go/subscribe
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
@ 2021-12-08 11:24 Thomas Kellerer <shammat@gmx.net>
parent: Paul Smith <paul@pscs.co.uk>
0 siblings, 0 replies; 5+ messages in thread
From: Thomas Kellerer @ 2021-12-08 11:24 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
Paul Smith schrieb am 08.12.2021 um 10:18:
>> I'm facing "Too many clients already" error frequently with my
>> PostgreSQL (v9.6.5) 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.
>>
> It is the responsibility of the client software to release
> connections when they are no longer needed. The server won't just
> time-out idle connections unless it is told to do so
Automatically closing idle sessions is only available since Postgres 14
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections
@ 2021-12-08 12:23 hubert depesz lubaczewski <depesz@depesz.com>
parent: Ron <ronljohnsonjr@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: hubert depesz lubaczewski @ 2021-12-08 12:23 UTC (permalink / raw)
To: Ron <ronljohnsonjr@gmail.com>; +Cc: pgsql-admin@lists.postgresql.org
On Wed, Dec 08, 2021 at 01:23:32AM -0600, Ron wrote:
> 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
> ;
Two notes:
1. it's better to use state_change and not query_start. For example, if
I'd start 2 hours query, 3 hours ago, then "now" it would still have
query_start at (now() - 3 hours), despite the fact that it would be
idle only for 1 hour.
2. doing calculations in epoch is bad idea. it can become your muscle
memory, and it will cause problems with indexing. instead:
and state_change < current_timestamp - '20 minutes'::interval
depesz
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2021-12-08 12:23 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 06:45 PostgreSQL(v9.6.5) not releasing old/inactive IDLE connections Md Arqum Farooqui <Md.Farooqui@india.nec.com>
2021-12-08 07:23 ` Ron <ronljohnsonjr@gmail.com>
2021-12-08 12:23 ` hubert depesz lubaczewski <depesz@depesz.com>
2021-12-08 09:18 ` Paul Smith <paul@pscs.co.uk>
2021-12-08 11:24 ` Thomas Kellerer <shammat@gmx.net>
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