From 791b6bacf100d5a26d956d0f81f5ab1cf850db36 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 26 Mar 2021 10:52:14 -0700
Subject: [PATCH v60 02/17] Schedule ShutdownXLOG() in single user mode using
 before_shmem_exit().

Previously on_shmem_exit() was used. The upcoming shared memory stats
patch uses DSM segments, which should not be used anymore after
the dsm_backend_shutdown() call in shmem_exit().  There does not seem
to be any reason to do ShutdownXLOG() via on_shmem_exit(), so change it.
---
 src/backend/utils/init/postinit.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 51d1bbef301..07f69e1f2db 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -661,7 +661,11 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
 		/* Reset CurrentResourceOwner to nothing for the moment */
 		CurrentResourceOwner = NULL;
 
-		on_shmem_exit(ShutdownXLOG, 0);
+		/*
+		 * Use before_shmem_exit() so that ShutdownXLOG() can rely on DSM
+		 * segments etc to work.
+		 */
+		before_shmem_exit(ShutdownXLOG, 0);
 	}
 
 	/*
-- 
2.31.0.121.g9198c13e34

