log_postmaster_stats

Поиск
Список
Период
Сортировка
Искать

log_postmaster_stats

От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
Вложения:
Hi -hackers,

We seem to have certain observability about postmaster
(pg_stat_database.{sessions,parallel_workers_launched}), but we do not have
pre-exisiting way to asses how much postmaster was really busy back in the
past. Even checkpointer (log_checkpoints) or startup recovery code is reporting
better what they were doing. One can say we have log_connections, yet bigger
shops cannot afford to log_connections all the time to count what happened
some time ago (and that can cumbersome anyway).

The attached patch introduces log_postmaster_stats in the same way we do have
log_startup_progress_interval, e.g. when set to 10 (seconds), it will show this
during artificial connection storm (log produced every 10s):

LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
parallel workers started/sec; CPU: user: 0.00 s, system: 0.00 s,
elapsed: 10.00 s
LOG:  postmaster stats: avg 1834.30 conns/sec; 1833.60 disconns/sec;
0.00 parallel workers started/sec; CPU: user: 0.12 s, system: 4.75 s,
elapsed: 9.96 s
LOG:  postmaster stats: avg 1055.75 conns/sec; 1056.25 disconns/sec;
0.00 parallel workers started/sec; CPU: user: 0.12 s, system: 4.27 s,
elapsed: 16.25 s
LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
parallel workers started/sec; CPU: user: 0.00 s, system: 0.00 s,
elapsed: 13.82 s
LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
parallel workers started/sec; CPU: user: 0.00 s, system: 0.00 s,
elapsed: 10.00 s

The interesting thing above is that the elapsed time is 6s (with the
setting at 10s), then one
can already tell there was a probem.

Known issues include connection storms, spotting low postmaster/fork()
efficency,
PQ workers causing startvation for new connections and so on. It is somehow
complementary to having those pg_stat_database counters mentioned at the
beggining. It is also complementary to the more recent log_connections with
=setup_durations, which logs timings, but not direct rate of forks()/second.

Another interesting thing above is that there can be discrepeancy
between user+system=~5s
against elapsed wall clock time=~10s above (it does not add up) and that's even
getrusage(RUSAGE_SELF and not RUSAGE_CHILDREN), but this comes apparently from
CPU scheduling at those kind of fork() rates. I was thinking about adding some
message like every now and then:
    "WARNING: postmaster potentially overloaded, stats not gathered in time"
however lot of folks don't like those self diagnosis messages, so that's not in
v1 patch today.

I've thought it would be good idea to actually to enable it by default (@60s?),
but right now it is off to be aligned with others.

Any hints/reviews are welcome.

-J.

Re: log_postmaster_stats

От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
On Wed, Jun 10, 2026 at 6:10 AM Quan Zongliang  wrote:
[..]
> When the database is idle for a long time. Will keep outputting
>
> LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
> parallel workers started/sec; CPU: user:  ...
> LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
> parallel workers started/sec; CPU: user:  ...
> LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
> parallel workers started/sec; CPU: user:  ...
>
> Could it be considered to reduce the output frequency when conn_delta,
> disc_delta and pqw_delta are all zero?
> Or until a new connection is established, then output the log for the
> idle period at one time. Just like:
>
> LOG:  postmaster stats: avg 0.00 conns/sec; 0.00 disconns/sec; 0.00
> parallel workers started/sec; CPU: user: 0.00 s, system: 0.00 s,
> elapsed: 1hours 10min 32s
> LOG:  postmaster stats: avg 0.30 conns/sec; 0.20 disconns/sec; 1.10
> parallel workers started/sec; CPU: user: 0.00 s, system: 0.00 s,
> elapsed: 10.00 s

Hi Quan,

thanks for trying out the patch! To be honest, I don't have opinion on
this, we could do that if there's community agreement to do this (or
some committer wants it this way or that way), but right now e.g.
checkpoint_timeout (which serves similiar purpose) does not behave
like that and always logs stuff and I was been told we should do
things consistently.

As for reducing logs volume, I think one could just use threshold
of 1 or 10 minutes (but while assessing some production issues one
could bump it down to every 1s temporarily just to have data to have
much better understandind what was system/postmaster doing).

-J.


Re: log_postmaster_stats

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Wed, Jun 10, 2026 at 3:24 AM Jakub Wartak
 wrote:
> thanks for trying out the patch! To be honest, I don't have opinion on
> this, we could do that if there's community agreement to do this (or
> some committer wants it this way or that way), but right now e.g.
> checkpoint_timeout (which serves similiar purpose) does not behave
> like that and always logs stuff and I was been told we should do
> things consistently.
>
> As for reducing logs volume, I think one could just use threshold
> of 1 or 10 minutes (but while assessing some production issues one
> could bump it down to every 1s temporarily just to have data to have
> much better understandind what was system/postmaster doing).

Well, on the immediate question, I think omitting the line altogether
when all the counters were zero would be sensible. I don't see who
would be helped by bloating the log volume in such a case.

But I would be really surprised if the overall design of this feature
didn't draw objections. I think what we normally do for features of
this type is include the relevant information in the cumulative
statistics system, and then leave it up to the user to decide how
often they want to poll the counters and how they want to summarize or
visualize the advancement of those counters. One could certainly make
an argument that having the information go to the log is a superior
user experience for people who don't need want, or need the complexity
of, an external tool. But it's going to be hard to justify why this
particular feature should be designed differently than all the other
features that do similar things.

-- 
Robert Haas
EDB: http://www.enterprisedb.com


Re: log_postmaster_stats

От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
Вложения:
On Mon, Jul 20, 2026 at 3:16 PM Robert Haas  wrote:
>
> On Wed, Jun 10, 2026 at 3:24 AM Jakub Wartak
>  wrote:
> > thanks for trying out the patch! To be honest, I don't have opinion on
> > this, we could do that if there's community agreement to do this (or
> > some committer wants it this way or that way), but right now e.g.
> > checkpoint_timeout (which serves similiar purpose) does not behave
> > like that and always logs stuff and I was been told we should do
> > things consistently.
> >
> > As for reducing logs volume, I think one could just use threshold
> > of 1 or 10 minutes (but while assessing some production issues one
> > could bump it down to every 1s temporarily just to have data to have
> > much better understandind what was system/postmaster doing).
>
> Well, on the immediate question, I think omitting the line altogether
> when all the counters were zero would be sensible. I don't see who
> would be helped by bloating the log volume in such a case.

OK, makes sense too.

> But I would be really surprised if the overall design of this feature
> didn't draw objections. I think what we normally do for features of
> this type is include the relevant information in the cumulative
> statistics system, and then leave it up to the user to decide how
> often they want to poll the counters and how they want to summarize or
> visualize the advancement of those counters. One could certainly make
> an argument that having the information go to the log is a superior
> user experience for people who don't need want, or need the complexity
> of, an external tool. But it's going to be hard to justify why this
> particular feature should be designed differently than all the other
> features that do similar things.

As I understand, You are trying to say that for every kind of observability
metric there might be, we always seem to have choice of 3:

a. put the metrics / fact into logs, e.g. log_startup_progress_interval
   (please see 9ce346eabf35), or log establishing every new connection
b. or put it into pg_stat* subsystem: e.g. like pg_stat_database.sessions (so
   already there somewhat)
c. not have it at all

The thing is that for single-threaded subsystems (postmaster,
postmaster/recovery, bgwriter, checkpointer, walsender) we seem not to have
any even approximate way of signaling to the DBAs the overload of the single
core capacity by those processes, especially on very active DBs (it's hard for
people to spot temporary spikes of single 100% CPU postmaster if one is having
like dozens of 100% CPU active backends all time on 128 VCPUs+; lots of people
miss this). So, the idea here is to have have something like easily accessible
built-in "pidstat 1" tracking at least for critical postmaster. The patch logs
something like:
   LOG: postmaster stats: avg 1055.75 conns/sec; 0.00 parallel workers
started/sec; CPU: user: 0.12 s, system: 4.27 s, ..
but my intention was more to capture the rusage data itself over date/time
rather than the conns/sec metric itself, but it is free addition and allows
easy correlation to the root-cause itself (parallel workers or new sessions).
Most of the time it is going to be flood of connections, but this $thread is
direct outcome of third reason: inefficiencies in fork() with 512GB s_b and
using kernel < 6.x (pre 6.0/or pre 6.5 kernels seems to lack certain hugetlb
optimizations for fork() + MAP_HUGEPAGES_2GB|MAP_SHARED), but there are also
other reasons why postmaster may really can suck in the field apparently,
please see [1]

So, cumuluative statistics seem to be never tracking historical information by
design and it seem to be never tracking CPU usage of anything (we could
capture maximum observed CPU usage for postmaster though between
pg_stat_reset*()s, not sure it would be good idea).

Those are related codepaths which kind of also inspired this:
1. xlogrecovery.c has errmsg("redo done at %X/%08X system usage: %s", ..
pg_rusage_show(&ru0)));
2. analyze/vacuum also log the same rusage()
3. checkpointer already does kind of similiar thing with "checkpoint complete:
time .. write=0.003 s, sync=0.001 s, total=0.017 s; "

-J.

[1] -
https://www.postgresql.org/message-id/flat/a5916f83-de79-4a40-933a-fb0d9ba2f5a0%40app.fastmail.com
,
especially the "For an example of scale, we have seen users with low connection
rates (<= 5 / minute) suddenly spike to between 2000 and 3000 connect
requests per
minute until the system grinds to a halt." (all due to PQ workers)


Re: log_postmaster_stats

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Jul 27, 2026 at 2:47 AM Jakub Wartak
 wrote:
> Now the GUC/concept is called log_excess_connection_attempts, however it is
> based on postmaster's CPU time or delay in getting CPU scheduled at all.
> I think name is nice, but one can argue it should be
> log_excess_postmaster_cpu_time too technically, but I find it way too long.

I think this is a good direction, but over the years I've acquired a
healthy skepticism of features where the documentation and the actual
behavior of the code drift apart like this. Since the feature name is
log_excess_connection_attempts, a user will tend to think that what
triggers the message is when there are a lot of connection attempts,
but it's actually trigger by high CPU usage or too much time passing
between consecutive points at which we consider logging the message.
What I think is bound to happen is that some users will not get a
message when one is expected (e.g. the number of connections is very
high but the computer handles it efficiently and so CPU usage remains
low) and others will get one when it's not expected (e.g. the
postmaster is slow because it get stuck reading or writing from the
disk or network, not because of a high connection rate).

Plus, checking the CPU usage like this is somewhat expensive, and I
doubt that high CPU usage over a 1 second period is even meaningful.

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.

-- 
Robert Haas
EDB: http://www.enterprisedb.com


Re: log_postmaster_stats

От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
Вложения:
On Thu, Jul 30, 2026 at 8:46 AM Jakub Wartak
 wrote:
>
> On Tue, Jul 28, 2026 at 4:00 PM Robert Haas  wrote:
> >
> > On Mon, Jul 27, 2026 at 2:47 AM Jakub Wartak
> >  wrote:
> > > Now the GUC/concept is called log_excess_connection_attempts, however it is
> > > based on postmaster's CPU time or delay in getting CPU scheduled at all.
> > > I think name is nice, but one can argue it should be
> > > log_excess_postmaster_cpu_time too technically, but I find it way too long.
> >
> > I think this is a good direction, but over the years I've acquired a
> > healthy skepticism of features where the documentation and the actual
> > behavior of the code drift apart like this. Since the feature name is
> > log_excess_connection_attempts, a user will tend to think that what
> > triggers the message is when there are a lot of connection attempts,
> > but it's actually trigger by high CPU usage or too much time passing
> > between consecutive points at which we consider logging the message.
>
> OK, I've renamed the CPU overload one to simply just log_postmaster_overloads
> and also added the log_postmaster_excess_connections=N for the reasons explained
> below.
>
> > Plus, checking the CPU usage like this is somewhat expensive, and I
> > doubt that high CPU usage over a 1 second period is even meaningful.
>
> getrusage() is pretty cheap actually as only use *if* that would be
> enabled by user + just called once every 1s (which itself compared
> to cap of 1-3 thousands of fork()/s is nothing I would say less than
> a noise?) + we use RUSAGE_SELF (so by definition it does not iterate on
> kernel side fo cpu time of all the possible children).
>
> > 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.
>
> So perhaps we could have two, (the main intention was to just stick to
> the CPU usage, but the v3 has bonus second GUC to allow what You just
> 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).
> While with setting raw number of connections with
> log_postmaster_excess_connections I've myself reproduced <200-300
> connections/s taking 100% sys for postmaster and it would never occur
> to me that I would have to set it up to such _low_ value.
>
> Anyway please just take a look on [1] to see that it might be not even
> obvious that connection startup might be a problem, but if we would even
> have this on by default such cases would be fairly trivial to solve in
> like seconds (just read the log) and there are fairly more examples
> where postmaster bottleneck can be an issue (people running apps usually
> do not have visibiity tracing of avg/p95/p99 database connection times
> until their apps crap out with errors that those connections failed
> due timeouts).
>
> -J.
>
> [1] - https://www.postgresql.org/message-id/CAFbpF8OA44_UG%2BRYJcWH9WjF7E3GA6gka3gvH6nsrSnEe9H0NA%40mail.gmail.com

I've got another occurence where this could be useful, so this pushed me into
polishing this patch. It still has two log_postmaster_excess_connections and
log_postmaster_overloads and they are both useful.

v4 attached, changes since last time:
- reset stats more often (when GUCs where enabled single spurious LOG emission
  happened with stats since the restart)
- add counting of accept()/fork() failures too (but not the max_conns hits as)
- convert "elapsed" from integer to double to make the math easier
- pgindent

One doubt I have is this: if both GUCs are enabled (with
log_postmaster_excess_connections set to e.g. value of 200), we get duplicate
LOG entries, but I thnk we could unitfy the LOG line in such case:

   2026-11-09 12:06:30.773 CET [751665] LOG:  postmaster potentially
overloaded, stats: avg 3179.96 conns/sec; 3178.96 disconns/sec; 0.00
conn errors/sec; 0.00 parallel workers started/sec; CPU: user: 0.02 s,
system: 0.97 s, elapsed: 1.00 s
   2026-11-09 12:06:30.773 CET [751665] LOG:  postmaster excessive
connections, stats: avg 3179.96 conns/sec; 3178.96 disconns/sec; 0.00
conn errors/sec; 0.00 parallel workers started/sec; CPU: user: 0.02 s,
system: 0.97 s, elapsed: 1.00 s
   2026-11-09 12:06:31.773 CET [751665] LOG:  postmaster potentially
overloaded, stats: avg 3177.37 conns/sec; 3179.37 disconns/sec; 0.00
conn errors/sec; 0.00 parallel workers started/sec; CPU: user: 0.02 s,
system: 0.97 s, elapsed: 1.00 s
   2026-11-09 12:06:31.773 CET [751665] LOG:  postmaster excessive
connections, stats: avg 3177.37 conns/sec; 3179.37 disconns/sec; 0.00
conn errors/sec; 0.00 parallel workers started/sec; CPU: user: 0.02 s,
system: 0.97 s, elapsed: 1.00 s
   [..]

instead we could do "postmaster overloaded and getting excessive connections,
stats: (..)",

-J.

Re: log_postmaster_stats

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
Sorry for the lengthy delay in responding.

On Thu, Jul 30, 2026 at 2:46 AM Jakub Wartak
 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.

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.
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, and you don't know
whether anything is actually wrong.

> 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.

-- 
Robert Haas
Databricks


Re: log_postmaster_stats

От:
Jakub Wartak <jakub.wartak@enterprisedb.com>
Дата:
On Fri, Nov 20, 2026 at 5:20 PM Robert Haas  wrote:

Hi Robert, thanks for taking a look!

> On Thu, Jul 30, 2026 at 2:46 AM Jakub Wartak
>  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.


Re: log_postmaster_stats

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Nov 23, 2026 at 4:51 AM Jakub Wartak
 wrote:
> > > 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?

Uh, neither of those, really. There are two things here that I don't like:

1. I don't like printing out a message that talks about possible
overload. It's fine to print out fact that may indicate to the
knowledgeable user that the postmaster is overloaded, but the message
wording should just be factual. Saying that there were %d connection
attempts in the last %d seconds is fine; saying that this potentially
indicates overload is too opinionated. Let the user decide what the
numbers mean.

2. I don't like using CPU usage to judge overload. I think it's
unreliable. I am not saying we should never have a setting that works
that way, but for me the bar to accept that would be very high. I'm
not completely certain that every "high CPU usage" alert I've ever
seen in my entire career was a false positive, but I am sure that the
false positives *greatly* outnumber the true positives, like by an
order of magnitude or more.

I feel pretty confident, for example, that on a typical system, >100
new connections per second is probably an indication of a problem.
Even if it doesn't produce high CPU usage, it is likely to produce
suboptimal results -- all of those new sessions will have constantly
cold caches. It might be a sign that the connection pooler isn't
working as intended, or that a connection pooler is not used but is
needed. Even when it's not an indication of a problem, like just after
a restart when something moves quickly to reestablish the connection
pool, the user will be well-placed to understand why it happened and
disregard it. On the other hand, I have limited confidence that the
postmaster running at >75% CPU is an indication of a problem, and no
confidence at all that it is an indication of *this specific problem*.
I suspect there are a bunch of things that could cause high CPU usage,
especially on tiny little machines, and I bet some of them are totally
benign, and others are real problems. Users who see this message won't
know if they have a real problem, and they also won't know what it is.
In my experience, that kind of message is unhelpful.

-- 
Robert Haas
Databricks


FAQ