From edabc369310562e6828f5877fc7944d9f3cb013a Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Sat, 18 Mar 2023 04:47:19 +0000
Subject: [PATCH v1] Fix misplaced shared_preload_libraries_in_progress check
 in few extensions

---
 contrib/pg_prewarm/autoprewarm.c         | 6 +++---
 src/test/modules/worker_spi/worker_spi.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 93835449c0..2c5520d70e 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -111,6 +111,9 @@ static int	autoprewarm_interval = 300; /* dump interval */
 void
 _PG_init(void)
 {
+	if (!process_shared_preload_libraries_in_progress)
+		return;
+
 	DefineCustomIntVariable("pg_prewarm.autoprewarm_interval",
 							"Sets the interval between dumps of shared buffers",
 							"If set to zero, time-based dumping is disabled.",
@@ -123,9 +126,6 @@ _PG_init(void)
 							NULL,
 							NULL);
 
-	if (!process_shared_preload_libraries_in_progress)
-		return;
-
 	/* can't define PGC_POSTMASTER variable after startup */
 	DefineCustomBoolVariable("pg_prewarm.autoprewarm",
 							 "Starts the autoprewarm worker.",
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index f536120bf1..3fc342764b 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -282,6 +282,9 @@ _PG_init(void)
 {
 	BackgroundWorker worker;
 
+	if (!process_shared_preload_libraries_in_progress)
+		return;
+
 	/* get the configuration */
 	DefineCustomIntVariable("worker_spi.naptime",
 							"Duration between each check (in seconds).",
@@ -296,9 +299,6 @@ _PG_init(void)
 							NULL,
 							NULL);
 
-	if (!process_shared_preload_libraries_in_progress)
-		return;
-
 	DefineCustomIntVariable("worker_spi.total_workers",
 							"Number of workers.",
 							NULL,
-- 
2.34.1

