Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXnZ-0007ri-QV for pgsql-general@arkaria.postgresql.org; Tue, 23 Nov 2021 15:33:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpXnY-0004rp-2J for pgsql-general@arkaria.postgresql.org; Tue, 23 Nov 2021 15:33:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXnX-0004rf-OU for pgsql-general@lists.postgresql.org; Tue, 23 Nov 2021 15:33:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpXnV-0003oM-BP for pgsql-general@postgresql.org; Tue, 23 Nov 2021 15:33:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1ANFXRYf4176161; Tue, 23 Nov 2021 10:33:27 -0500 From: Tom Lane To: James Sewell cc: pgsql-general Subject: Re: Max connections reached without max connections reached In-reply-to: References: Comments: In-reply-to James Sewell message dated "Tue, 23 Nov 2021 17:08:59 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4176159.1637681607.1@sss.pgh.pa.us> Date: Tue, 23 Nov 2021 10:33:27 -0500 Message-ID: <4176160.1637681607@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk James Sewell writes: > The system handles a lot of connections - we have a max_connections of 600. > Most are long lived JDBC, but there are a lot of ETL / ad-hoc jobs etc. > Connections normally sit at 300ish, with 70 active at the most. The > machines have 32 CPU cores . PgBouncer is sadly not an option hereas we are > using many long lived connections which make use of prepared statements. > Sometimes a strange condition occurs. The number of connections is well > under 600 (and dropping), but new connections are not being allowed into > the database, I can see this message in the logs: > (0:53300)FATAL: remaining connection slots are reserved for > non-replication superuser connections What are you looking at to claim the number of connections is under 600? Maybe there's some disconnect between what you're measuring and what the database thinks. A different line of thought is that ProcArray slots can be consumed by things that aren't client connection processes, in particular (1) parallel-query workers (2) autovacuum workers Looking into pg_stat_activity when you see this issue might help clarify that. regards, tom lane