From b454a1ab5867b308f9bd138c3db687f0014f849b Mon Sep 17 00:00:00 2001
From: Yushu Chen <gentcys@gmail.com>
Date: Sat, 23 May 2026 20:02:03 +0800
Subject: [PATCH v1] regress test create database with locale encoding mismatch

src/test/regress/sql/database.sql does not have regression coverage
for the failure case described in the documentation
https://www.postgresql.org/docs/current/sql-createdatabase.html

"The specified locale and encoding settings must match,
or an error will be reported."

Author: Yushu Chen <gentcys@gmail.com>
---
 src/test/regress/expected/database.out | 5 +++++
 src/test/regress/sql/database.sql      | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/src/test/regress/expected/database.out b/src/test/regress/expected/database.out
index 6b879b0f62a..50089ff46e1 100644
--- a/src/test/regress/expected/database.out
+++ b/src/test/regress/expected/database.out
@@ -4,6 +4,11 @@ ALTER DATABASE regression_tbd RENAME TO regression_utf8;
 ALTER DATABASE regression_utf8 SET TABLESPACE regress_tblspace;
 ALTER DATABASE regression_utf8 SET TABLESPACE pg_default;
 ALTER DATABASE regression_utf8 CONNECTION_LIMIT 123;
+-- Test raises an error when locale and encoding mismatch.
+CREATE DATABASE regression_locale_encoding_not_match
+	LOCALE "en_US.UTF-8" ENCODING LATIN9 TEMPLATE template0;
+ERROR:  encoding "LATIN9" does not match locale "en_US.UTF-8"
+DETAIL:  The chosen LC_CTYPE setting requires encoding "UTF8".
 -- Test PgDatabaseToastTable.  Doing this with GRANT would be slow.
 BEGIN;
 UPDATE pg_database
diff --git a/src/test/regress/sql/database.sql b/src/test/regress/sql/database.sql
index 4ef36127291..95063c851ac 100644
--- a/src/test/regress/sql/database.sql
+++ b/src/test/regress/sql/database.sql
@@ -4,6 +4,9 @@ ALTER DATABASE regression_tbd RENAME TO regression_utf8;
 ALTER DATABASE regression_utf8 SET TABLESPACE regress_tblspace;
 ALTER DATABASE regression_utf8 SET TABLESPACE pg_default;
 ALTER DATABASE regression_utf8 CONNECTION_LIMIT 123;
+-- Test raises an error when locale and encoding mismatch.
+CREATE DATABASE regression_locale_encoding_not_match
+	LOCALE "en_US.UTF-8" ENCODING LATIN9 TEMPLATE template0;
 
 -- Test PgDatabaseToastTable.  Doing this with GRANT would be slow.
 BEGIN;
-- 
2.50.1 (Apple Git-155)

