Re: Getting error "too many clients already" despite having a db connection limit set

From: Richard Welty <rwelty(at)salesium(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "adolfo flores" <adolfoflores2211(at)gmail(dot)com>, "pgsql-general" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Getting error "too many clients already" despite having a db connection limit set
Date: 2025-06-16 16:59:57
Message-ID: 19779aef09c.f35a7edd116750.8002494421662785732@salesium.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

a coding error i've seen from inexperienced devs with little database experience

is inattentiveness to how the DB connections were being opened. last time i

saw this, a smart young dev with no DB background did not understand the cost

of opening connections and had on the order of 30 php calls to open connections

to PostgreSQL in a single page. he did not understand why it was slow.

richard

---- On Mon, 16 Jun 2025 12:39:09 -0400 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote ---

adolfo flores < mailto:adolfoflores2211(at)gmail(dot)com > writes:
> I hope you can help me with an issue we're experiencing. We have an app
> running on Kubernetes that opens a huge number of connections within a
> couple of seconds.

You need to fix that app to be less unfriendly, or maybe put it behind
a connection pooler.

> Is it expected behavior to reach the max_connections limit when that app
> opens many connections in a short period of time, even if a connection
> limit is set for that database and everything else uses no more than 10% of
> the max_connections?

It takes a finite amount of time for a new backend process to figure
out which database it's supposed to connect to and then detect whether
the per-DB connection limit is exceeded. In the meantime, that
session does count against the global limit, so yeah this isn't
surprising if the connection arrival rate is high enough.

            regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-06-16 17:21:39 Re: Getting error "too many clients already" despite having a db connection limit set
Previous Message Marco Torres 2025-06-16 16:41:44 Re: Getting error "too many clients already" despite having a db connection limit set