From 12f98d966d458b551028cd99a10c3c02bfebab37 Mon Sep 17 00:00:00 2001
From: Greg Sabino Mullane <greg@turnstep.com>
Date: Wed, 5 Jun 2024 14:31:57 -0400
Subject: [PATCH] Give a more accurate error message if one of the magic "first
 arg" options to postgres is not given first.

---
 src/backend/postmaster/postmaster.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index bf0241aed0..dce8f7795e 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -617,6 +617,15 @@ PostmasterMain(int argc, char *argv[])
 					ParseLongOption(optarg, &name, &value);
 					if (!value)
 					{
+						if (strcmp(optarg, "boot") == 0 ||
+							strcmp(optarg, "check") == 0 ||
+							strcmp(optarg, "describe-config") == 0 ||
+							strcmp(optarg, "fork") == 0 ||
+							strcmp(optarg, "single") == 0)
+						{
+							write_stderr("--%s must be first argument.\n", optarg);
+							ExitPostmaster(1);
+						}
 						if (opt == '-')
 							ereport(ERROR,
 									(errcode(ERRCODE_SYNTAX_ERROR),
-- 
2.30.2

