On 2017-09-16 13:27:05 -0700, Andres Freund wrote: > > This does not seem like a problem that justifies a system-wide change > > that's much more delicate than you thought. > > We need one more initialization call during crash-restart - that doesn't > seem particularly hard a fix.
FWIW, attached is that simple fix. Not quite ready for commit - needs more comments, thoughts and a glass of wine less to commit. I'll try to come up with a tap test that tests crash restarts tomorrow - not sure if there's a decent way to trigger one on windows without writing a C function. Will play around with that tomorrow. - Andres
>From 6728a5f4620270c1a116e295f316536861a317f4 Mon Sep 17 00:00:00 2001 From: Andres Freund <and...@anarazel.de> Date: Sun, 17 Sep 2017 01:00:39 -0700 Subject: [PATCH] Preliminary fix for crash-restart. --- src/backend/access/transam/xlog.c | 4 ++-- src/backend/postmaster/postmaster.c | 6 +++++- src/backend/tcop/postgres.c | 2 +- src/include/access/xlog.h | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b8f648927a..b475e3fb6b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -4808,9 +4808,9 @@ check_wal_buffers(int *newval, void **extra, GucSource source) * memory. XLOGShemInit() will then copy it to shared memory later. */ void -LocalProcessControlFile(void) +LocalProcessControlFile(bool reset) { - Assert(ControlFile == NULL); + Assert(reset || ControlFile == NULL); ControlFile = palloc(sizeof(ControlFileData)); ReadControlFile(); } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index e4f8f597c6..7ccf8dbd9d 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -951,7 +951,7 @@ PostmasterMain(int argc, char *argv[]) CreateDataDirLockFile(true); /* read control file (error checking and contains config) */ - LocalProcessControlFile(); + LocalProcessControlFile(false); /* * Initialize SSL library, if specified. @@ -3829,6 +3829,10 @@ PostmasterStateMachine(void) ResetBackgroundWorkerCrashTimes(); shmem_exit(1); + + /* re-read control file into local memory */ + LocalProcessControlFile(true); + reset_shared(PostPortNumber); StartupPID = StartupDataBase(); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 46b662266b..dfd52b3c87 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -3718,7 +3718,7 @@ PostgresMain(int argc, char *argv[], CreateDataDirLockFile(false); /* read control file (error checking and contains config ) */ - LocalProcessControlFile(); + LocalProcessControlFile(false); /* Initialize MaxBackends (if under postmaster, was done already) */ InitializeMaxBackends(); diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index e0635ab4e6..7213af0e81 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -261,7 +261,7 @@ extern XLogRecPtr GetFakeLSNForUnloggedRel(void); extern Size XLOGShmemSize(void); extern void XLOGShmemInit(void); extern void BootStrapXLOG(void); -extern void LocalProcessControlFile(void); +extern void LocalProcessControlFile(bool reset); extern void StartupXLOG(void); extern void ShutdownXLOG(int code, Datum arg); extern void InitXLOGAccess(void); -- 2.14.1.536.g6867272d5b.dirty
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers