Re: make MaxBackends available in _PG_init
Julien Rouhaud <rjuju123@gmail.com>
From: Julien Rouhaud <rjuju123@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael@paquier.xyz>, Robert Haas <robertmhaas@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, "Bossart, Nathan" <bossartn@amazon.com>, Fujii Masao <masao.fujii@oss.nttdata.com>, "wangsh.fnst@fujitsu.com" <wangsh.fnst@fujitsu.com>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Greg Sabino Mullane <htamfids@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2022-03-26T07:22:03Z
Lists: pgsql-hackers
Hi, On Fri, Mar 25, 2022 at 03:23:17PM -0700, Andres Freund wrote: > > I don't really understand. The issue that started this thread was bugs in > extensions due to accessing MaxBackends before it is initialized - which the > patch prevents. Well, the patch prevents accessing a 0-valued MaxBackends but doesn't do anything to solve the original complaint. It's not like extensions won't need to access that information during _PG_init anymore. > The stuff that you're complaining about / designing here > doesn't seem related to that. I like the idea of the hooks etc, but I fail to > see why we "ought to revisit the business with GetMaxBackends()"? Because this GetMaxBackends() doesn't solve the problem nor brings any infrastructure that could be reused to solve it. I think that the root issue could be rephrased with: Can we initialize MaxBackends earlier so that _PG_init() can see it because maintaining MaxConnections + autovacuum_max_workers + 1 + max_worker_processes + max_wal_senders is troublesome. And indeed, any third party code that previously needed to access what MaxBackends is supposed to store should already be using that formula, and the new GetMaxBackends() doesn't do anything about it. So all extensions will be as broken as before, except the few that were using MaxBackends without realizing it's 0. And if those exist (there's actually one) they're not that broken, probably because MaxBackend is only used to request additional shmem, with wanted value small enough so that it's compensated by the extra 100kB shmem postgres allocates. Since all those underlying GUCs shouldn't be accessible, we need some more general infrastructure that would work for those too on top of a way to access MaxBackends when extensions needs it. Note that the only use case I'm aware of is for RequestAddinShmemSpace, so a hook after _PG_init like the example shmem_request_hook would be enough for the latter, but maybe there are more use cases for which it wouldn't.
Commits
-
Add a new shmem_request_hook hook.
- 4f2400cb3f10 15.0 landed
-
Remove non-functional code for unloading loadable modules.
- ab02d702ef08 15.0 landed
-
Fix misleading comments about background worker registration.
- 701d918a426b 15.0 landed
-
Revert the addition of GetMaxBackends() and related stuff.
- 7fc0e7de9fb8 15.0 landed
-
Fix typo in multixact.c
- 0147fc7c8c92 15.0 landed
-
Reduce more the number of calls to GetMaxBackends()
- 4567596316d1 15.0 landed
-
Remove MaxBackends variable in favor of GetMaxBackends() function.
- aa64f23b0292 15.0 landed
-
Fix comments about bgworker registration before MaxBackends initialization
- 5ecd0183fb6a 15.0 landed
-
Fix bogus assertion in BootstrapModeMain().
- e12694523e7e 15.0 cited
-
Make sure MaxBackends is always set
- dfbba2c86cc8 9.3.0 cited