From 33c6ce1cf9cae75d833aa268885dc23e1149f69d Mon Sep 17 00:00:00 2001
From: Lucas Jeffrey <luquijeffrey@gmail.com>
Date: Sun, 8 Nov 2026 18:31:45 -0300
Subject: [PATCH] postgres_fdw: Set the value of global variable
 postgres_fdw_options after initialization is completed

---
 contrib/postgres_fdw/option.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 5b539c4eeef..14c87173ab4 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -239,6 +239,7 @@ InitPgFdwOptions(void)
 	PQconninfoOption *libpq_options;
 	PQconninfoOption *lopt;
 	PgFdwOption *popt;
+	PgFdwOption *head;
 
 	/* non-libpq FDW-specific FDW options */
 	static const PgFdwOption non_libpq_options[] = {
@@ -327,12 +328,13 @@ InitPgFdwOptions(void)
 	 * Construct an array which consists of all valid options for
 	 * postgres_fdw, by appending FDW-specific options to libpq options.
 	 */
-	postgres_fdw_options = (PgFdwOption *)
+	head = (PgFdwOption *)
 		MemoryContextAlloc(TopMemoryContext,
 						   sizeof(PgFdwOption) * num_libpq_opts +
 						   sizeof(non_libpq_options));
 
-	popt = postgres_fdw_options;
+
+	popt = head;
 	for (lopt = libpq_options; lopt->keyword; lopt++)
 	{
 		/* Hide debug options, as well as settings we override internally. */
@@ -369,6 +371,8 @@ InitPgFdwOptions(void)
 
 	/* Append FDW-specific options and dummy terminator. */
 	memcpy(popt, non_libpq_options, sizeof(non_libpq_options));
+
+	postgres_fdw_options = head;
 }
 
 /*
-- 
2.43.0

