From 4d4c837371fc66850b9499d30dcad43b1f5a764d Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Wed, 22 Apr 2026 15:09:27 -0700
Subject: [PATCH v1.17] Guard against uninitialized default locale.

No known problem today, but defend against issues like dbf217c1c7 in
the future.

Backpatch-through: 17
---
 src/backend/utils/adt/pg_locale.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index aa0114ce120..7a51b953f0a 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1361,6 +1361,10 @@ lc_collate_is_c(Oid collation)
 		if (result >= 0)
 			return (bool) result;
 
+		/* should not happen */
+		if (default_locale.provider == '\0')
+			elog(ERROR, "default locale not initialized");
+
 		if (default_locale.provider == COLLPROVIDER_BUILTIN)
 		{
 			result = true;
@@ -1428,6 +1432,10 @@ lc_ctype_is_c(Oid collation)
 		if (result >= 0)
 			return (bool) result;
 
+		/* should not happen */
+		if (default_locale.provider == '\0')
+			elog(ERROR, "default locale not initialized");
+
 		if (default_locale.provider == COLLPROVIDER_BUILTIN)
 		{
 			localeptr = default_locale.info.builtin.locale;
@@ -1586,6 +1594,10 @@ pg_newlocale_from_collation(Oid collid)
 
 	if (collid == DEFAULT_COLLATION_OID)
 	{
+		/* should not happen */
+		if (default_locale.provider == '\0')
+			elog(ERROR, "default locale not initialized");
+
 		if (default_locale.provider == COLLPROVIDER_LIBC)
 			return (pg_locale_t) 0;
 		else
-- 
2.43.0

