Re: make MaxBackends available in _PG_init
Nathan Bossart <nathandbossart@gmail.com>
From: Nathan Bossart <nathandbossart@gmail.com>
To: Julien Rouhaud <rjuju123@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>, Michael Paquier <michael@paquier.xyz>, "Bossart, Nathan" <bossartn@amazon.com>, Fujii Masao <masao.fujii@oss.nttdata.com>, "wangsh.fnst@fujitsu.com" <wangsh.fnst@fujitsu.com>, Andres Freund <andres@anarazel.de>, 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-24T20:20:50Z
Lists: pgsql-hackers
On Wed, Mar 23, 2022 at 09:03:18PM +0800, Julien Rouhaud wrote: > On Wed, Mar 23, 2022 at 08:32:39AM -0400, Robert Haas wrote: >> Well, the conclusion upthread was that extensions might change the >> values of those GUCs from _PG_init(). If that's a real thing, then >> what you're asking for here is impossible, because the final value is >> indeterminate until all such extensions have finished twiddling those >> the GUCs. On the other hand, it's definitely intended that extensions >> should RequestAddinShmemSpace() from _PG_init(), and wanting to size >> that memory based on MaxBackends is totally reasonable. Do we need to >> add another function, alongside _PG_init(), that gets called after >> MaxBackends is determined and before it's too late to >> RequestAddinShmemSpace()? > > Yes, I don't see how we can support such extensions without an additional hook, > probably called right after InitializeMaxBackends() since at least > InitializeShmemGUCs() will need to know about those extra memory needs. Another possibility could be to add a hook that is called _before_ _PG_init() where libraries are permitted to adjust GUCs. After the library is loaded, we first call this _PG_change_GUCs() function, then we initialize MaxBackends, and then we finally call _PG_init(). This way, extensions would have access to MaxBackends within _PG_init(), and if an extension really needed to alter GUCs, іt could define this new function. > I'm not sure how to prevent third party code from messing with the gucs in it, > but a clear indication in the hook comment should probably be enough. It's not > like it's hard for third-party code author to break something anyway. ERROR-ing in SetConfigOption() might be another way to dissuade folks from messing with GUCs. This is obviously not a perfect solution. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com
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