diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 6066c4784f4..e61a2026d6f 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -3187,7 +3187,7 @@ SCRAM-SHA-256$<iteration count>:&l
datcollatetext
- LC_COLLATE for this database (ignored unless datlocprovider is c)
+ LC_COLLATE for this database
diff --git a/doc/src/sgml/charset.sgml b/doc/src/sgml/charset.sgml
index 746e40bb9d2..89760466c1f 100644
--- a/doc/src/sgml/charset.sgml
+++ b/doc/src/sgml/charset.sgml
@@ -100,7 +100,7 @@ initdb --locale=sv_SE
LC_COLLATE
- String sort order (ignored unless the provider is libc)
+ String sort orderLC_CTYPE
diff --git a/doc/src/sgml/ref/create_database.sgml b/doc/src/sgml/ref/create_database.sgml
index 3544b15efda..4da8aeebb50 100644
--- a/doc/src/sgml/ref/create_database.sgml
+++ b/doc/src/sgml/ref/create_database.sgml
@@ -150,12 +150,12 @@ CREATE DATABASE name
Sets the default collation order and character classification in the
new database. Collation affects the sort order applied to strings,
- e.g., in queries with ORDER BY, as well as the
- order used in indexes on text columns. Character classification
- affects the categorization of characters, e.g., lower, upper, and
- digit. Also sets the LC_CTYPE aspect of the
- operating system environment. The default is the same setting as the
- template database. See ORDER BY, as well as the order used in indexes
+ on text columns. Character classification affects the categorization
+ of characters, e.g., lower, upper, and digit. Also sets the
+ associated aspects of the operating system environment,
+ LC_COLLATE and LC_CTYPE. The
+ default is the same setting as the template database. See and for details.
@@ -189,16 +189,17 @@ CREATE DATABASE namelc_collate
- If is
- libc, sets the default collation order to use in
- the new database, overriding the setting . Otherwise, this setting is
- ignored.
+ Sets LC_COLLATE in the database server's operating
+ system environment. The default is the setting of if specified, otherwise the same
+ setting as the template database. See below for additional
+ restrictions.
- The default is the setting of
- if specified, otherwise the same setting as the template database.
- See below for additional restrictions.
+ If is
+ libc, also sets the default collation order to use
+ in the new database, overriding the setting .
@@ -207,18 +208,16 @@ CREATE DATABASE name
Sets LC_CTYPE in the database server's operating
- system environment.
+ system environment. The default is the setting of if specified, otherwise the same
+ setting as the template database. See below for additional
+ restrictions.
If is
- libc, sets the default character classification to
- use in the new database, overriding the setting .
-
-
- The default is the setting of
- if specified, otherwise the same setting as the template database.
- See below for additional restrictions.
+ libc, also sets the default character
+ classification to use in the new database, overriding the setting
+ .
diff --git a/doc/src/sgml/ref/createdb.sgml b/doc/src/sgml/ref/createdb.sgml
index 2ccbe13f390..5c4e0465ed9 100644
--- a/doc/src/sgml/ref/createdb.sgml
+++ b/doc/src/sgml/ref/createdb.sgml
@@ -136,8 +136,7 @@ PostgreSQL documentation
- Specifies the LC_COLLATE setting to be used in this database (ignored
- unless the locale provider is libc).
+ Specifies the LC_COLLATE setting to be used in this database.
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 7b9b602f3c4..f44021fa68f 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -125,17 +125,13 @@ main(int argc, char *argv[])
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres"));
/*
- * Collation is handled by pg_locale.c, and the behavior is dependent on
- * the provider. strcoll(), etc., should not be called directly.
- */
- init_locale("LC_COLLATE", LC_COLLATE, "C");
-
- /*
- * In the postmaster, absorb the environment value for LC_CTYPE.
- * Individual backends will change it later to pg_database.datctype, but
- * the postmaster cannot do that. If we leave it set to "C" then message
- * localization might not work well in the postmaster.
+ * In the postmaster, absorb the environment values for LC_COLLATE and
+ * LC_CTYPE. Individual backends will change these later to settings
+ * taken from pg_database, but the postmaster cannot do that. If we leave
+ * these set to "C" then message localization might not work well in the
+ * postmaster.
*/
+ init_locale("LC_COLLATE", LC_COLLATE, "");
init_locale("LC_CTYPE", LC_CTYPE, "");
/*
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 3d8c9bdebd5..8b6ea195eca 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -432,11 +432,12 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
datum = SysCacheGetAttrNotNull(DATABASEOID, tup, Anum_pg_database_datctype);
ctype = TextDatumGetCString(datum);
- /*
- * Historically, we set LC_COLLATE from datcollate, as well. That's no
- * longer necessary because all collation behavior is handled through
- * pg_locale_t.
- */
+ if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)
+ ereport(FATAL,
+ (errmsg("database locale is incompatible with operating system"),
+ errdetail("The database was initialized with LC_COLLATE \"%s\", "
+ " which is not recognized by setlocale().", collate),
+ errhint("Recreate the database with another locale or install the missing locale.")));
if (pg_perm_setlocale(LC_CTYPE, ctype) == NULL)
ereport(FATAL,