initdb: change default --locale-provider back to libc.

Reverts 27b62377b4.

Discussion: https://postgr.es/m/eff031036baa07f325de29215371a4c9e69d61f3.camel@j-davis.com
Discussion: https://postgr.es/m/3353947.1682092131@sss.pgh.pa.us
This commit is contained in:
Jeff Davis 2023-06-21 11:10:03 -07:00
parent 555b929bbe
commit 2535c74b1a
8 changed files with 29 additions and 55 deletions

View File

@ -93,24 +93,10 @@ PostgreSQL documentation
</para> </para>
<para> <para>
By default, <command>initdb</command> uses the ICU library to provide By default, <command>initdb</command> uses the locale provider
locale services if the server was built with ICU support; otherwise it uses <literal>libc</literal> (see <xref linkend="locale-providers"/>). The
the <literal>libc</literal> locale provider (see <xref <literal>libc</literal> locale provider takes the locale settings from the
linkend="locale-providers"/>). To choose the specific ICU locale ID to environment, and determines the encoding from the locale settings.
apply, use the option <option>--icu-locale</option>. Note that for
implementation reasons and to support legacy code,
<command>initdb</command> will still select and initialize libc locale
settings when the ICU locale provider is used.
</para>
<para>
Alternatively, <command>initdb</command> can use the locale provider
<literal>libc</literal>. To select this option, specify
<literal>--locale-provider=libc</literal>, or build the server without ICU
support. The <literal>libc</literal> locale provider takes the locale
settings from the environment, and determines the encoding from the locale
settings. This is almost always sufficient, unless there are special
requirements.
</para> </para>
<para> <para>
@ -122,6 +108,16 @@ PostgreSQL documentation
this should be used with care. this should be used with care.
</para> </para>
<para>
Alternatively, <command>initdb</command> can use the ICU library to provide
locale services by specifying <literal>--locale-provider=icu</literal>. The
server must be built with ICU support. To choose the specific ICU locale ID
to apply, use the option <option>--icu-locale</option>. Note that for
implementation reasons and to support legacy code,
<command>initdb</command> will still select and initialize libc locale
settings when the ICU locale provider is used.
</para>
<para> <para>
When <command>initdb</command> runs, it will print out the locale settings When <command>initdb</command> runs, it will print out the locale settings
it has chosen. If you have complex requirements or specified multiple it has chosen. If you have complex requirements or specified multiple
@ -251,11 +247,6 @@ PostgreSQL documentation
Specifies the ICU locale when the ICU provider is used. Locale support Specifies the ICU locale when the ICU provider is used. Locale support
is described in <xref linkend="locale"/>. is described in <xref linkend="locale"/>.
</para> </para>
<para>
If this option is not specified, the locale is inherited from the
environment in which <command>initdb</command> runs. The environment's
locale is matched to a similar ICU locale name, if possible.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -330,9 +321,8 @@ PostgreSQL documentation
This option sets the locale provider for databases created in the new This option sets the locale provider for databases created in the new
cluster. It can be overridden in the <command>CREATE cluster. It can be overridden in the <command>CREATE
DATABASE</command> command when new databases are subsequently DATABASE</command> command when new databases are subsequently
created. The default is <literal>icu</literal> if the server was created. The default is <literal>libc</literal> (see <xref
built with ICU support; otherwise the default is linkend="locale-providers"/>).
<literal>libc</literal> (see <xref linkend="locale-providers"/>).
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -143,11 +143,7 @@ static char *lc_monetary = NULL;
static char *lc_numeric = NULL; static char *lc_numeric = NULL;
static char *lc_time = NULL; static char *lc_time = NULL;
static char *lc_messages = NULL; static char *lc_messages = NULL;
#ifdef USE_ICU
static char locale_provider = COLLPROVIDER_ICU;
#else
static char locale_provider = COLLPROVIDER_LIBC; static char locale_provider = COLLPROVIDER_LIBC;
#endif
static char *icu_locale = NULL; static char *icu_locale = NULL;
static char *icu_rules = NULL; static char *icu_rules = NULL;
static const char *default_text_search_config = NULL; static const char *default_text_search_config = NULL;
@ -2357,19 +2353,6 @@ icu_validate_locale(const char *loc_str)
#endif #endif
} }
/*
* Determine the default ICU locale
*/
static char *
default_icu_locale(void)
{
#ifdef USE_ICU
return pg_strdup(uloc_getDefault());
#else
pg_fatal("ICU is not supported in this build");
#endif
}
/* /*
* set up the locale variables * set up the locale variables
* *
@ -2429,10 +2412,7 @@ setlocales(void)
/* acquire default locale from the environment, if not specified */ /* acquire default locale from the environment, if not specified */
if (icu_locale == NULL) if (icu_locale == NULL)
{ pg_fatal("ICU locale must be specified");
icu_locale = default_icu_locale();
printf(_("Using default ICU locale \"%s\".\n"), icu_locale);
}
/* canonicalize to a language tag */ /* canonicalize to a language tag */
langtag = icu_language_tag(icu_locale); langtag = icu_language_tag(icu_locale);
@ -3273,7 +3253,6 @@ main(int argc, char *argv[])
break; break;
case 8: case 8:
locale = "C"; locale = "C";
locale_provider = COLLPROVIDER_LIBC;
break; break;
case 9: case 9:
pwfilename = pg_strdup(optarg); pwfilename = pg_strdup(optarg);

View File

@ -103,6 +103,11 @@ SKIP:
if ($ENV{with_icu} eq 'yes') if ($ENV{with_icu} eq 'yes')
{ {
command_fails_like(
[ 'initdb', '--no-sync', '--locale-provider=icu', "$tempdir/data2" ],
qr/initdb: error: ICU locale must be specified/,
'locale provider ICU requires --icu-locale');
command_ok( command_ok(
[ [
'initdb', '--no-sync', 'initdb', '--no-sync',

View File

@ -1965,7 +1965,7 @@ my %tests = (
create_sql => create_sql =>
"CREATE DATABASE dump_test2 LOCALE = 'C' TEMPLATE = template0;", "CREATE DATABASE dump_test2 LOCALE = 'C' TEMPLATE = template0;",
regexp => qr/^ regexp => qr/^
\QCREATE DATABASE dump_test2 \E.*\QLOCALE = 'C'\E \QCREATE DATABASE dump_test2 \E.*\QLOCALE = 'C';\E
/xm, /xm,
like => { pg_dumpall_dbprivs => 1, }, like => { pg_dumpall_dbprivs => 1, },
}, },

View File

@ -13,7 +13,7 @@ program_version_ok('createdb');
program_options_handling_ok('createdb'); program_options_handling_ok('createdb');
my $node = PostgreSQL::Test::Cluster->new('main'); my $node = PostgreSQL::Test::Cluster->new('main');
$node->init(extra => ['--locale-provider=libc']); $node->init;
$node->start; $node->start;
$node->issues_sql_like( $node->issues_sql_like(

View File

@ -12,7 +12,7 @@ if ($ENV{with_icu} ne 'yes')
} }
my $node1 = PostgreSQL::Test::Cluster->new('node1'); my $node1 = PostgreSQL::Test::Cluster->new('node1');
$node1->init(extra => ['--locale-provider=libc']); $node1->init;
$node1->start; $node1->start;
$node1->safe_psql('postgres', $node1->safe_psql('postgres',

View File

@ -1023,7 +1023,7 @@ SET client_min_messages TO WARNING;
do $$ do $$
BEGIN BEGIN
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' || EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');'; quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
END END
$$; $$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
@ -1031,7 +1031,7 @@ ERROR: collation "test0" already exists
do $$ do $$
BEGIN BEGIN
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' || EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');'; quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
END END
$$; $$;
RESET client_min_messages; RESET client_min_messages;

View File

@ -362,14 +362,14 @@ SET client_min_messages TO WARNING;
do $$ do $$
BEGIN BEGIN
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' || EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');'; quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
END END
$$; $$;
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
do $$ do $$
BEGIN BEGIN
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' || EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');'; quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
END END
$$; $$;