Re: make MaxBackends available in _PG_init
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Nathan Bossart <nathandbossart@gmail.com>,
Andres Freund <andres@anarazel.de>, Julien Rouhaud <rjuju123@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>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Greg Sabino Mullane <htamfids@gmail.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2022-04-13T15:25:43Z
Lists: pgsql-hackers
On Wed, Apr 13, 2022 at 10:43 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Yeah, there is something to be said for preventing subtle interactions > between extensions. > > > So in the end I see basically four possibilities here: > > > A. No hard compatibility break, but invent a set-a-GUC hook that runs earlier. > > B. No hard compatibility break, but invent a request-shmem hook that runs later. > > C. Invent a set-a-GUC hook that runs earlier AND refuse to set GUCs in _PG_init. > > D. Invent a request-shmem hook that runs later AND refuse to accept > > shmem requests in _PG_init. > > I dislike A for the reason I already stated: _PG_init should be the > first code we run in an extension. Not doing that is just too hacky > for words. That seems like a fair position, even if I don't really understand why it would be as bad as "too hacky for words." > While B breaks the least stuff in the short run, I agree > that it leaves extension authors on the hook to avoid unpleasant > interactions, and that the only way they can be sure to do so is > to move their shmem requests to the new hook. So if we're willing > to accept a hard compatibility break to prevent such bugs, then > I too prefer D to C. What I'm not quite convinced about is whether > the problem is big enough to warrant a compatibility break. It's sort of a philosophical question. How do you measure the size of such a problem? What units do you even use for such a size measurement? How big does it have to be to justify a compatibility break? Presumably it depends on the size of the compatibility break, which is also not subject to any sort of objective measurement. I guess my feeling about this is that _PG_init() is sort of a grab bag, and that's not very good. You're supposed to register new GUCs there, and request shared memory space, and install any hook functions you want to use, and maybe some other stuff. But why is it appropriate for all of those things to happen at the same time? I think it pretty clearly isn't, and that's why you see _PG_init() functions testing process_shared_preload_libraries_in_progress, and why RequestAddinShmemSpace() is a no-op if it's not the right time for such things. To me, all of that is just a sign that the system is badly designed. Imagine if someone proposed to make XLogInsert() or SetConfigOption() or LockBuffer() sometimes just return without doing anything. We would just call those functions in places where those actions weren't appropriate, and the function would just do nothing silently without signalling an error. Surely such a proposal would be shot down as an awful idea, and the only reason the _PG_init() case is any different is because it's not new. But it doesn't seem to me that it's any better of an idea here than it would be there. And under proposal D we'd actually be fixing that, because we'd have a hook that is the right place to request shared memory and we'd complain if those functions were called from anywhere else. -- Robert Haas EDB: http://www.enterprisedb.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