diff options
author | Fujii Masao <fujii@postgresql.org> | 2021-04-06 02:25:37 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2021-04-06 02:27:48 +0900 |
commit | e3bf9621632cc369fbedd15743daf17e55f8db62 (patch) | |
tree | 0b5fd072e9522a3b310e7cfa98b7e6a73a5e236a /src/backend/postmaster/startup.c | |
parent | 605ef23c7c0fb44f841ec8f1f588325dd8fc951e (diff) |
Shut down transaction tracking at startup process exit.
Maxim Orlov reported that the shutdown of standby server could result in
the following assertion failure. The cause of this issue was that,
when the shutdown caused the startup process to exit, recovery-time
transaction tracking was not shut down even if it's already initialized,
and some locks the tracked transactions were holding could not be released.
At this situation, if other process was invoked and the PGPROC entry that
the startup process used was assigned to it, it found such unreleased locks
and caused the assertion failure, during the initialization of it.
TRAP: FailedAssertion("SHMQueueEmpty(&(MyProc->myProcLocks[i]))"
This commit fixes this issue by making the startup process shut down
transaction tracking and release all locks, at the exit of it.
Back-patch to all supported branches.
Reported-by: Maxim Orlov
Author: Fujii Masao
Reviewed-by: Maxim Orlov
Discussion: https://postgr.es/m/ad4ce692cc1d89a093b471ab1d969b0b@postgrespro.ru
Diffstat (limited to 'src/backend/postmaster/startup.c')
-rw-r--r-- | src/backend/postmaster/startup.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c index 9d964f17111..2fe41c01ad1 100644 --- a/src/backend/postmaster/startup.c +++ b/src/backend/postmaster/startup.c @@ -53,6 +53,9 @@ static void StartupProcSigUsr1Handler(SIGNAL_ARGS); static void StartupProcTriggerHandler(SIGNAL_ARGS); static void StartupProcSigHupHandler(SIGNAL_ARGS); +/* Callbacks */ +static void StartupProcExit(int code, Datum arg); + /* -------------------------------- * signal handler routines @@ -164,6 +167,19 @@ HandleStartupProcInterrupts(void) } +/* -------------------------------- + * signal handler routines + * -------------------------------- + */ +static void +StartupProcExit(int code, Datum arg) +{ + /* Shutdown the recovery environment */ + if (standbyState != STANDBY_DISABLED) + ShutdownRecoveryTransactionEnvironment(); +} + + /* ---------------------------------- * Startup Process main entry point * ---------------------------------- @@ -171,6 +187,9 @@ HandleStartupProcInterrupts(void) void StartupProcessMain(void) { + /* Arrange to clean up at startup process exit */ + on_shmem_exit(StartupProcExit, 0); + /* * Properly accept or ignore signals the postmaster might send us. */ |