Re: fix bgworkers in EXEC_BACKEND

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: fix bgworkers in EXEC_BACKEND
Date: 2012-12-31 21:06:39
Message-ID: 20121231210639.GS4363@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas wrote:
> On 27.12.2012 22:46, Alvaro Herrera wrote:
> >Heikki Linnakangas wrote:
> >
> >>Might be cleaner to directly assign the correct value to MaxBackends
> >>above, ie. "MaxBackends = MaxConnections + newval + 1 +
> >>GetNumShmemAttachedBgworkers()". With a comment to remind that it
> >>needs to be kept in sync with the other places where that
> >>calculation is done, in guc.c. Or put that calculation in a new
> >>function and call it above and in guc.c.
> >>
> >>Thinking about this some more, it might be cleaner to move the
> >>responsibility of setting MaxBackends out of guc.c, into
> >>postmaster.c. The guc machinery would set max_connections and
> >>autovacuum_max_workers as usual, but not try to set MaxBackends.
> >>After reading the config file in postmaster.c, calculate
> >>MaxBackends.

Actually this patch still needed one more change, because we weren't
rechecking that we're not beyond the MAX_BACKENDS value after bgworker
registration.

This is hard to hit, because with the current compile constants you need
over eight million backends in total to hit that limit (and 360 GB of
shared memory), but it seems dangerous to leave that without any
protection.

I kinda hate this a bit because I had to move MAX_BACKENDS from a
private value in guc.c to postmaster.h. But the wording of the error
message is what took the most time:

+ ereport(LOG,
+ (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
+ errmsg("too many background workers"),
+ errdetail("Up to %d background workers can be registered with the current settings.",
+ MAX_BACKENDS - (MaxConnections + autovacuum_max_workers + 1))));

Completely different ideas for this error message are welcome. My first
try enumerated all the variables involved.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
calculate-MaxBackends-in-postmaster-3.patch text/x-diff 7.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2012-12-31 21:35:51 Re: dynamic SQL - possible performance regression in 9.2
Previous Message Pavel Stehule 2012-12-31 20:32:29 unexpected query result on hot standby server