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 1joBBs-0007Yd-VI for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 19:36:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joBBr-0004Dv-SO for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 19:36:11 +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 1joBBr-0004Di-KU for pgsql-general@lists.postgresql.org; Wed, 24 Jun 2020 19:36:11 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joBBn-0001ir-Mx for pgsql-general@lists.postgresql.org; Wed, 24 Jun 2020 19:36:10 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 60040330D; Wed, 24 Jun 2020 21:36:05 +0200 (CEST) Date: Wed, 24 Jun 2020 21:36:05 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Persistent Connections Message-ID: <20200624193605.GB15882@hjp.at> References: <20200624104736.GB417@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rJwd6BRFiFCcLxzm" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --rJwd6BRFiFCcLxzm Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-06-24 13:55:00 -0400, Bee.Lists wrote: > On Jun 24, 2020, at 6:47 AM, Peter J. Holzer wrote: > > The default is 100. What was your reason for reducing it to such a low > > value? >=20 > =E2=80=9CPostgreSQL 9 High Availability=E2=80=9D recommended core count *= 3. =20 I suspected something like that. I don't have that book, but I assume that the author meant that as a limit on parallel active queries. An idle connection uses (almost) no CPU, so it doesn't make sense to include it in the count.=20 The question is, how do you enforce that limit? Setting max_connections on the database is no good: It will prevent new connections after the limit is reached, but the application doesn't know why its getting errors. Instead you have to limit the application. If all/most of your database accesses come from a single web application, configure that application to open at most 12 connections (there may be an explicit pool size configuration setting, or you may have to limit that implicitely through the number of threads and/or processses). If you have several apps, you might want to configure each to a lower limit so that the sum doesn't exceed 12. But if you have configured your web app to 12 connections, you still want max_connections to be higher: You want to be able to connect with psql even when your web app is running at peak capacity. You want to run your cron jobs. So always leave some head room. > >> I=E2=80=99ve installed pg_stat_activity and pg_stat_statements. > >>=20 > >> I access this server through a web app, > >=20 > > So that's probably a handful connections already. >=20 > Looks like 5 queries. =20 >=20 > As a comparison I have 37 queries asking for last login of a single user.= No errors.=20 > (I increased the max_connections yesterday) Does "I have 37 queries" mean you have seen 37 queries of this type in some time window (e.g. the last day or hour) or does it mean you are currently seeing 37 connections where the last query was of this type? If it's the latter, you very obviously have at least 37 (more likely 37 + 5 =3D 42) connections. So you web app is configured to open dozens of connections concurrently. You might want to look into that. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --rJwd6BRFiFCcLxzm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl7zqxsACgkQ8g5IURL+ KF050g//cbyuFSQW/nuDoKbPI8ssPPdvwHT3FLoRAG6VdSWYiWSiFCGSp3aNwtu4 GjdlMjXBHu/dt1aE8Lw2F2lm8KVxMrzYCpYvcvbJmRo1us6BJG5xTAZgFykiZ7lW yL2m2YG3pUQbYoI6kzA6lrqWPJHKTMg5+GjiSa4CdQBobehLjuzpGW9Z/bACX0Tt PAa/ZRDxxM8IZ6R+ldW62syxAJhIbznrZlNmKocgg+uKdrGH/VLcMhiVKLqWomI5 vOrv691bhl4gco1MBWnCucUe1jhiQVZu1grrlLRUN0hdqRLooFUx6dROYlMc5nMw FQlSHnjgIo9SGVq1hYXHDdErE7eoYXS8xHHYLxzAl0KqiUcYtjDo00wuD+CgLZJu 9WXGaTZs2ur+sxo4p5DIQQ4h1Pf/O4AgcxO3eNxxTWDIN49LV5RGCYndRq2cuWl9 nfvQjKPsJ4NzHJhT9oqz8QH0W9G/ojUaJxfHx6YYo9p9b4V01KHZIPZW9sbPJekN qTgdmYV6FccUZIP84gRvuERAHrHT2EixzUa2jnqMjk54CFpL9WHreeyM0bh+GbK9 pNUwivpWG4M35NQWR3IHa8MkMAvGOdpq0KLcdwTkKA2Fjyx0n+HVFE4s5+1e8pgp MrWof/FtpX1oSlt4Ko4sdFrURpLNudVelaGgdFv3h3so7zntEsQ= =nPJW -----END PGP SIGNATURE----- --rJwd6BRFiFCcLxzm--