On 09.05.23 10:25, Alvaro Herrera wrote:
On 2023-Apr-24, Peter Eisentraut wrote:
The GUC settings lc_collate and lc_ctype are from a time when those locale
settings were cluster-global. When we made those locale settings
per-database (PG 8.4), we kept them as read-only. As of PG 15, you can use
ICU as the per-database locale provider, so what is being attempted in the
above example is already meaningless before PG 16, since you need to look
into pg_database to find out what is really happening.
I think we should just remove the GUC parameters lc_collate and lc_ctype.
I agree with removing these in v16, since they are going to become more
meaningless and confusing.
Here is my proposed patch for this.
From b548a671ad02a5c851a4984db6e4535a0b70f881 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 11 May 2023 13:02:02 +0200
Subject: [PATCH] Remove read-only server settings lc_collate and lc_ctype
The GUC settings lc_collate and lc_ctype are from a time when those
locale settings were cluster-global. When those locale settings were
made per-database (PG 8.4), the settings were kept as read-only. As
of PG 15, you can use ICU as the per-database locale provider, so
examining these settings is already meaningless, since you need to
look into pg_database to find out what is really happening.
Discussion:
https://www.postgresql.org/message-id/696054d1-bc88-b6ab-129a-18b8bce6a...@enterprisedb.com
---
contrib/citext/expected/citext_utf8.out | 4 +--
contrib/citext/expected/citext_utf8_1.out | 4 +--
contrib/citext/sql/citext_utf8.sql | 4 +--
doc/src/sgml/config.sgml | 32 -------------------
src/backend/utils/init/postinit.c | 4 ---
src/backend/utils/misc/guc_tables.c | 26 ---------------
.../regress/expected/collate.icu.utf8.out | 4 +--
.../regress/expected/collate.linux.utf8.out | 6 ++--
.../expected/collate.windows.win1252.out | 6 ++--
src/test/regress/sql/collate.icu.utf8.sql | 4 +--
src/test/regress/sql/collate.linux.utf8.sql | 6 ++--
.../regress/sql/collate.windows.win1252.sql | 6 ++--
12 files changed, 22 insertions(+), 84 deletions(-)
diff --git a/contrib/citext/expected/citext_utf8.out
b/contrib/citext/expected/citext_utf8.out
index 77b4586d8f..6630e09a4d 100644
--- a/contrib/citext/expected/citext_utf8.out
+++ b/contrib/citext/expected/citext_utf8.out
@@ -8,8 +8,8 @@
* to the "tr-TR-x-icu" collation where it will succeed.
*/
SELECT getdatabaseencoding() <> 'UTF8' OR
- current_setting('lc_ctype') = 'C' OR
- (SELECT datlocprovider='i' FROM pg_database
+ (SELECT (datlocprovider = 'c' AND datctype = 'C') OR datlocprovider =
'i'
+ FROM pg_database
WHERE datname=current_database())
AS skip_test \gset
\if :skip_test
diff --git a/contrib/citext/expected/citext_utf8_1.out
b/contrib/citext/expected/citext_utf8_1.out
index d1e1fe1a9d..3caa7a00d4 100644
--- a/contrib/citext/expected/citext_utf8_1.out
+++ b/contrib/citext/expected/citext_utf8_1.out
@@ -8,8 +8,8 @@
* to the "tr-TR-x-icu" collation where it will succeed.
*/
SELECT getdatabaseencoding() <> 'UTF8' OR
- current_setting('lc_ctype') = 'C' OR
- (SELECT datlocprovider='i' FROM pg_database
+ (SELECT (datlocprovider = 'c' AND datctype = 'C') OR datlocprovider =
'i'
+ FROM pg_database
WHERE datname=current_database())
AS skip_test \gset
\if :skip_test
diff --git a/contrib/citext/sql/citext_utf8.sql
b/contrib/citext/sql/citext_utf8.sql
index 8530c68dd7..1f51df134b 100644
--- a/contrib/citext/sql/citext_utf8.sql
+++ b/contrib/citext/sql/citext_utf8.sql
@@ -9,8 +9,8 @@
*/
SELECT getdatabaseencoding() <> 'UTF8' OR
- current_setting('lc_ctype') = 'C' OR
- (SELECT datlocprovider='i' FROM pg_database
+ (SELECT (datlocprovider = 'c' AND datctype = 'C') OR datlocprovider =
'i'
+ FROM pg_database
WHERE datname=current_database())
AS skip_test \gset
\if :skip_test
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 909a3f28c7..3e9030e3d7 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -10788,38 +10788,6 @@ <title>Preset Options</title>
</listitem>
</varlistentry>
- <varlistentry id="guc-lc-collate" xreflabel="lc_collate">
- <term><varname>lc_collate</varname> (<type>string</type>)
- <indexterm>
- <primary><varname>lc_collate</varname> configuration parameter</primary>
- </indexterm>
- </term>
- <listitem>
- <para>
- Reports the locale in which sorting of textual data is done.
- See <xref linkend="locale"/> for more information.
- This value is determined when a database is created.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry id="guc-lc-ctype" xreflabel="lc_ctype">
- <term><varname>lc_ctype</varname> (<type>string</type>)
- <indexterm>
- <primary><varname>lc_ctype</varname> configuration parameter</primary>
- </indexterm>
- </term>
- <listitem>
- <para>
- Reports the locale that determines character classifications.
- See <xref linkend="locale"/> for more information.
- This value is determined when a database is created.
- Ordinarily this will be the same as <varname>lc_collate</varname>,
- but for special applications it might be set differently.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry id="guc-max-function-args" xreflabel="max_function_args">
<term><varname>max_function_args</varname> (<type>integer</type>)
<indexterm>
diff --git a/src/backend/utils/init/postinit.c
b/src/backend/utils/init/postinit.c
index 53420f4974..df81e35eb8 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -483,10 +483,6 @@ CheckMyDatabase(const char *name, bool am_superuser, bool
override_allow_connect
quote_identifier(name))));
}
- /* Make the locale settings visible as GUC variables, too */
- SetConfigOption("lc_collate", collate, PGC_INTERNAL,
PGC_S_DYNAMIC_DEFAULT);
- SetConfigOption("lc_ctype", ctype, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
-
ReleaseSysCache(tup);
}
diff --git a/src/backend/utils/misc/guc_tables.c
b/src/backend/utils/misc/guc_tables.c
index 5f90aecd47..23d4b38e72 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -563,8 +563,6 @@ static char *syslog_ident_str;
static double phony_random_seed;
static char *client_encoding_string;
static char *datestyle_string;
-static char *locale_collate;
-static char *locale_ctype;
static char *server_encoding_string;
static char *server_version_string;
static int server_version_num;
@@ -4050,30 +4048,6 @@ struct config_string ConfigureNamesString[] =
NULL, NULL, NULL
},
- /* See main.c about why defaults for LC_foo are not all alike */
-
- {
- {"lc_collate", PGC_INTERNAL, PRESET_OPTIONS,
- gettext_noop("Shows the collation order locale."),
- NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
- },
- &locale_collate,
- "C",
- NULL, NULL, NULL
- },
-
- {
- {"lc_ctype", PGC_INTERNAL, PRESET_OPTIONS,
- gettext_noop("Shows the character classification and
case conversion locale."),
- NULL,
- GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
- },
- &locale_ctype,
- "C",
- NULL, NULL, NULL
- },
-
{
{"lc_messages", PGC_SUSET, CLIENT_CONN_LOCALE,
gettext_noop("Sets the language in which messages are
displayed."),
diff --git a/src/test/regress/expected/collate.icu.utf8.out
b/src/test/regress/expected/collate.icu.utf8.out
index b5a221b030..21840815c9 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1023,7 +1023,7 @@ SET client_min_messages TO WARNING;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT daticulocale FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@@ -1031,7 +1031,7 @@ ERROR: collation "test0" already exists
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT daticulocale FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
RESET client_min_messages;
diff --git a/src/test/regress/expected/collate.linux.utf8.out
b/src/test/regress/expected/collate.linux.utf8.out
index 6d34667ceb..01664f7c1b 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -1027,7 +1027,7 @@ CREATE SCHEMA test_schema;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@@ -1039,9 +1039,9 @@ NOTICE: collation "test0" for encoding "UTF8" already
exists, skipping
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (lc_collate = ' ||
- quote_literal(current_setting('lc_collate')) ||
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) ||
', lc_ctype = ' ||
- quote_literal(current_setting('lc_ctype')) || ');';
+ quote_literal((SELECT datctype FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail, need lc_ctype
diff --git a/src/test/regress/expected/collate.windows.win1252.out
b/src/test/regress/expected/collate.windows.win1252.out
index 61b421161f..b7b93959de 100644
--- a/src/test/regress/expected/collate.windows.win1252.out
+++ b/src/test/regress/expected/collate.windows.win1252.out
@@ -863,7 +863,7 @@ CREATE SCHEMA test_schema;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@@ -875,9 +875,9 @@ NOTICE: collation "test0" for encoding "WIN1252" already
exists, skipping
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (lc_collate = ' ||
- quote_literal(current_setting('lc_collate')) ||
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) ||
', lc_ctype = ' ||
- quote_literal(current_setting('lc_ctype')) || ');';
+ quote_literal((SELECT datctype FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail, need lc_ctype
diff --git a/src/test/regress/sql/collate.icu.utf8.sql
b/src/test/regress/sql/collate.icu.utf8.sql
index 85e26951b6..c9c2ab8fa6 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -362,14 +362,14 @@ CREATE SCHEMA test_schema;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT daticulocale FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT daticulocale FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
diff --git a/src/test/regress/sql/collate.linux.utf8.sql
b/src/test/regress/sql/collate.linux.utf8.sql
index 2b787507c5..132d13af0a 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -359,7 +359,7 @@ CREATE SCHEMA test_schema;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@@ -368,9 +368,9 @@ CREATE COLLATION IF NOT EXISTS test0 (locale = 'foo'); --
ok, skipped
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (lc_collate = ' ||
- quote_literal(current_setting('lc_collate')) ||
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) ||
', lc_ctype = ' ||
- quote_literal(current_setting('lc_ctype')) || ');';
+ quote_literal((SELECT datctype FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail, need lc_ctype
diff --git a/src/test/regress/sql/collate.windows.win1252.sql
b/src/test/regress/sql/collate.windows.win1252.sql
index b5c45e1810..353d769a5b 100644
--- a/src/test/regress/sql/collate.windows.win1252.sql
+++ b/src/test/regress/sql/collate.windows.win1252.sql
@@ -310,7 +310,7 @@ CREATE SCHEMA test_schema;
do $$
BEGIN
EXECUTE 'CREATE COLLATION test0 (locale = ' ||
- quote_literal(current_setting('lc_collate')) || ');';
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@@ -319,9 +319,9 @@ CREATE COLLATION IF NOT EXISTS test0 (locale = 'foo'); --
ok, skipped
do $$
BEGIN
EXECUTE 'CREATE COLLATION test1 (lc_collate = ' ||
- quote_literal(current_setting('lc_collate')) ||
+ quote_literal((SELECT datcollate FROM pg_database WHERE datname =
current_database())) ||
', lc_ctype = ' ||
- quote_literal(current_setting('lc_ctype')) || ');';
+ quote_literal((SELECT datctype FROM pg_database WHERE datname =
current_database())) || ');';
END
$$;
CREATE COLLATION test3 (lc_collate = 'en_US.utf8'); -- fail, need lc_ctype
--
2.40.0