From: Jeff Davis <pgsql@j-davis.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: [15] Custom WAL resource managers, single user mode, and recovery
Date: Fri, 15 Jul 2022 12:43:52 -0700
Message-ID: <5f35eb43799f99ec49d0280a8628e88c0932cad4.camel@j-davis.com> (raw)
In-Reply-To: <3192874.1657846137@sss.pgh.pa.us>
References: <9decc18a42634f8a2f15c97a385a0f51a752f396.camel@j-davis.com>
<3192874.1657846137@sss.pgh.pa.us>
On Thu, 2022-07-14 at 20:48 -0400, Tom Lane wrote:
> I think that the patch might be missing some stuff. In postmaster.c,
> there are several steps after process_shared_preload_libraries()
> that look to be there to support loadable libraries, such as
> process_shmem_requests(). Wouldn't it be reasonable to expect
> that a loadable library would malfunction without those?
New patch attached.
This can also be a problem for custom table AMs, if the AM is expecting
to be loaded in shared_preload_libraries. For instance, it would be
reasonable for a module to have in _PG_init() something like:
if (!process_shared_preload_libraries_in_progress)
elog(ERROR, "module must be loaded in shared_preload_libraries");
to ensure hooks are properly configured at the right time. But if the
module does something like that, and also implements a custom table AM,
then it breaks single-user mode entirely because you can no longer do a
database-wide VACUUM.
I'm debating whether to backport this just to v15, where custom wal
resource managers were introduced, or all the way back to v12, where
custom table AMs were introduced. I'm inclined to just go to 15,
because the issue with table AMs is more of a gotcha than a real bug.
Regards,
Jeff Davis
Attachments:v2-0001-Process-shared_preload_libraries-in-single-user-mode.patch (text/x-patch, 2.0K) download
From 5e9a5526d8c6fc1cf8d27dc800e892840940a0ba Mon Sep 17 00:00:00 2001
From: Jeff Davis <jdavis@postgresql.org>
Date: Fri, 15 Jul 2022 12:24:10 -0700
Subject: [PATCH] Process shared_preload_libraries in single-user mode.
Without processing shared_preload_libraries, it's impossible to
recover if custom WAL resource managers are needed. It may also pose a
problem running VACUUM on a table with a custom AM, if the module
implementing the AM is expecting to be loaded by
shared_preload_libraries.
The reason this wasn't done before was just the general principle to
do fewer things in single-user mode. But it's easy enough to just set
shared_preload_libraries to empty, for the same effect.
Discussion: https://postgr.es/m/9decc18a42634f8a2f15c97a385a0f51a752f396.camel%40j-davis.com
Reviewed-by: Tom Lane, Andres Freund
Backpatch-through: 15
---
src/backend/tcop/postgres.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.cindex 6f18b68856..8ba1c170f0 100644--- a/src/backend/tcop/postgres.c+++ b/src/backend/tcop/postgres.c@@ -3933,9 +3933,32 @@ PostgresSingleUserMain(int argc, char *argv[],
/* read control file (error checking and contains config ) */
LocalProcessControlFile(false);
+ /*+ * process any libraries that should be preloaded at postmaster start+ */+ process_shared_preload_libraries();+
/* Initialize MaxBackends */
InitializeMaxBackends();
+ /*+ * Give preloaded libraries a chance to request additional shared memory.+ */+ process_shmem_requests();++ /*+ * Now that loadable modules have had their chance to request additional+ * shared memory, determine the value of any runtime-computed GUCs that+ * depend on the amount of shared memory required.+ */+ InitializeShmemGUCs();++ /*+ * Now that modules have been loaded, we can process any custom resource+ * managers specified in the wal_consistency_checking GUC.+ */+ InitializeWalConsistencyChecking();+
CreateSharedMemoryAndSemaphores();
/*
--
2.25.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: pgsql@j-davis.com, tgl@sss.pgh.pa.us
Subject: Re: [15] Custom WAL resource managers, single user mode, and recovery
In-Reply-To: <5f35eb43799f99ec49d0280a8628e88c0932cad4.camel@j-davis.com>
References: <9decc18a42634f8a2f15c97a385a0f51a752f396.camel@j-davis.com> <3192874.1657846137@sss.pgh.pa.us> <5f35eb43799f99ec49d0280a8628e88c0932cad4.camel@j-davis.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox