Re: log_postmaster_stats

From: Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Quan Zongliang <quanzongliang(at)yeah(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: log_postmaster_stats
Date: 2026-11-23 09:51:37
Message-ID: CAKZiRmwg9mYTGr6wOwm0C5pAkXLu_bQp6Nz4ZoA3w1qywcbiAA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 20, 2026 at 5:20 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

Hi Robert, thanks for taking a look!

> On Thu, Jul 30, 2026 at 2:46 AM Jakub Wartak
> <jakub(dot)wartak(at)enterprisedb(dot)com> wrote:
> > > I suspect the right thing to do here is drop all the CPU usage stuff
> > > and just make it a test for whether the connection rate is high. Then
> > > you could also make the value of the parameter an integer, like:
> > > log_excessive_connection_rate=100 to log whenever there are >=100
> > > connection in 1 second. That gives the parameter a very specific
> > > charter that is easy to guess even from just looking at the name. A
> > > side benefit of this is that you could write a test that would pass
> > > reliably; just set log_excessive_connection_rate=1 and try to connect.
> > > 1 >= 1 so a message should appear.
> >
> > The problem with just the raw new sessions/s is that how the user is
> > supposed to know to which value set it to? She/he could observe
> > rate of pg_stat_database.{sessions,parallel_workers_launched}, and based
> > to come up with average and then set it up to some value.
>
> Well, that's a problem, but your CPU-based version isn't better in
> that regard. It thinks anything above 75% CPU usage within a single
> second is too much, and it's not configurable at all. If my proposed
> configuration knob is hard to tune, yours has no option to tune
> anything. I don't think that can be better.

Fair point , I think we could make it tunable and with something like 'at
least N seconds with over Y% CPU' (log_postmaster_overloads='75%:3s' - parse
a string). That would be better, right? I'm open to any other suggestions
before doing next round.

> Also, my experience is that people who monitor for high CPU usage
> often find it, but the false-positive rate tends to be very high. When
> people say "oh no, my server has high CPU consumption!" my gut
> reaction is "what do you think CPUs are for? did you pay for them so
> they could sit idle?". This isn't quite the same, because you're not
> measuring system-wide CPU usage but the postmaster specifically, and
> we know 100% is a hard ceiling, and not a very high one in 2026. But
> at the same time, my guess is that if we install something like this
> it will find various ways of going off, at least occasionally, that
> are not indicative of a real problem, or that are not indicative of
> connection overload. And whether they are or not, nobody will know
> after the fact whether it was a real problem or an imaginary one.

I can provide counterargument easily: if I would be having a car, I would
prefer one one with oil temperature gauge, regardless of cause.

Anyway, with customizable setting of e.g. '75%:3s' we are potentially talking
about 3*~3k= 9k connections, so if that LOG entry would fire I bet there *is*
a problem (especially if max_connections is lower and it's just churn). If one
adds to the context that there are application guys complaining that 'database
has connection problems', it allows quick way for operators to do fast root-
cause identification toward fixing the app(s) - most of the time app devs
and DBAs in big shops are separate teams and having clear communication
(clear LOG entries) is way to go IMHO (unlike writing scripts to parse/measure
/graph some connection floods, please e.g. see custom graph from attached
production incident for illustration sample of the problem).

> Hypothetically speaking, if an EDB customer finds 35 instances of this
> log message in their postgres log over a week, what are you going to
> tell them? There's nothing actionable there: you can't find out why it
> happened, you can't prevent it from happening,

It depends, if they ask in the context of "our app guys are reporting database
having issues with connections" or just generic question "what does that mean"
(without any issues)

In the first case, business as usual:
* that PostgreSQL has built-in and unresolved architectural limitation since
day one, it has no clear path to getting around it.
* that they can usually do ~1k-3k connection/s maximum (but if
something it can be even just as low as 300-800 conns/s). BTW: I'm coming
here for this lower value (e.g I can tell you that certain 3rd party
security XDR/EDR solutions can have impact on postmaster up to ~40%
overhead)
* somehow you cannot see that until you start doing pidstat and BPF (how's
that supposed to be user friendly?)
* and that they need to fix their apps and/or deploy connection pooler

The second case (some random signals without more problems) could be
potentially attributed to lack of spread startup of app(s) (not doing roll-
over) OR if that's just single app server then tune the native app it's
connection pooling to have lower "minimum" conn-pool setting (often app
servers during startup request hundredths of conns all at once, it's
misconfiguration). I think most of those false positives could still be
silenced thanks to this customizable (longer) interval.

> and you don't know whether anything is actually wrong.

IMO getting constant and regular spikes of activity from postmaster *is* wrong
and sign of lack of control on outband connectivity of the apps. You need to
have some headroom and with values over 75% or more , there's not a lot of
it. I've always believed that queuing theory applied to CPU and without the
headroom to absorb bursts, latency is gonna grow non-linearly (signature of
unstable system). Anyway my take is not to have it on by default, just be able
to discover it when it's needed, same way like log_connections=setup_durations

I think it's way better with the feature as You are getting sign that stuff is
overloaded (details of impl. yet to be finalized), rather than uselessly
logging thousands of "connection received" lines, which nobody
really reads, so yes I'm saying that log_connections=on is spam and we could
do better. One could argue that users are supposed to look at pg_stat_database.
sessions, but I bet it's way too hard to use it to connect the dots (and one
would need fast-sampling, while most external monitoring queries it every M
minutes).

There's also another thing free thing, the log info already covers situations
where CPU pressure for fork() coming from new connections spikes could explain
impact to BGW/PQ queries being used or not (the parallel_workers_to_launch !=
parallel_workers_launched), like this:

LOG: postmaster potentially overloaded, stats: avg 1028.16 conns/sec;
1017.16 disconns/sec; 0.00 conn errors/sec; 607.30 parallel workers
started/sec; CPU: user: 0.03 s, system: 1.20 s, elapsed: 2.00 s
LOG: postmaster potentially overloaded, stats: avg 1041.31 conns/sec;
1039.32 disconns/sec; 0.00 conn errors/sec; 902.67 parallel workers
started/sec; CPU: user: 0.02 s, system: 1.50 s, elapsed: 2.00 s

> > described). With CPU usage, I think people would agree that anything
> > >=70-80% is clear sign of overload (so that's just nice on/off toggle).
>
> To be absolutely clear, I do not agree with that and strongly suspect
> it isn't generally true.

Hm, so you do not agree on the specific threshold values used or on the whole
idea of having information of overloaded specific subsystem?

-J.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-23 10:00:01 Re: Detect mismatched subscription and replication slot properties
Previous Message Rajesh Kumar Thandapani 2026-11-23 09:46:45 Re: Bug in logical decoding with DDL and subtransactions