Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2535c74

Browse files
committed
1 parent 555b929 commit 2535c74

File tree

8 files changed

+29
-55
lines changed

8 files changed

+29
-55
lines changed

doc/src/sgml/ref/initdb.sgml

+16-26
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,10 @@ PostgreSQL documentation
9393
</para>
9494

9595
<para>
96-
By default, <command>initdb</command> uses the ICU library to provide
97-
locale services if the server was built with ICU support; otherwise it uses
98-
the <literal>libc</literal> locale provider (see <xref
99-
linkend="locale-providers"/>). To choose the specific ICU locale ID to
100-
apply, use the option <option>--icu-locale</option>. Note that for
101-
implementation reasons and to support legacy code,
102-
<command>initdb</command> will still select and initialize libc locale
103-
settings when the ICU locale provider is used.
104-
</para>
105-
106-
<para>
107-
Alternatively, <command>initdb</command> can use the locale provider
108-
<literal>libc</literal>. To select this option, specify
109-
<literal>--locale-provider=libc</literal>, or build the server without ICU
110-
support. The <literal>libc</literal> locale provider takes the locale
111-
settings from the environment, and determines the encoding from the locale
112-
settings. This is almost always sufficient, unless there are special
113-
requirements.
96+
By default, <command>initdb</command> uses the locale provider
97+
<literal>libc</literal> (see <xref linkend="locale-providers"/>). The
98+
<literal>libc</literal> locale provider takes the locale settings from the
99+
environment, and determines the encoding from the locale settings.
114100
</para>
115101

116102
<para>
@@ -122,6 +108,16 @@ PostgreSQL documentation
122108
this should be used with care.
123109
</para>
124110

111+
<para>
112+
Alternatively, <command>initdb</command> can use the ICU library to provide
113+
locale services by specifying <literal>--locale-provider=icu</literal>. The
114+
server must be built with ICU support. To choose the specific ICU locale ID
115+
to apply, use the option <option>--icu-locale</option>. Note that for
116+
implementation reasons and to support legacy code,
117+
<command>initdb</command> will still select and initialize libc locale
118+
settings when the ICU locale provider is used.
119+
</para>
120+
125121
<para>
126122
When <command>initdb</command> runs, it will print out the locale settings
127123
it has chosen. If you have complex requirements or specified multiple
@@ -251,11 +247,6 @@ PostgreSQL documentation
251247
Specifies the ICU locale when the ICU provider is used. Locale support
252248
is described in <xref linkend="locale"/>.
253249
</para>
254-
<para>
255-
If this option is not specified, the locale is inherited from the
256-
environment in which <command>initdb</command> runs. The environment's
257-
locale is matched to a similar ICU locale name, if possible.
258-
</para>
259250
</listitem>
260251
</varlistentry>
261252

@@ -330,9 +321,8 @@ PostgreSQL documentation
330321
This option sets the locale provider for databases created in the new
331322
cluster. It can be overridden in the <command>CREATE
332323
DATABASE</command> command when new databases are subsequently
333-
created. The default is <literal>icu</literal> if the server was
334-
built with ICU support; otherwise the default is
335-
<literal>libc</literal> (see <xref linkend="locale-providers"/>).
324+
created. The default is <literal>libc</literal> (see <xref
325+
linkend="locale-providers"/>).
336326
</para>
337327
</listitem>
338328
</varlistentry>

src/bin/initdb/initdb.c

+1-22
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ static char *lc_monetary = NULL;
143143
static char *lc_numeric = NULL;
144144
static char *lc_time = NULL;
145145
static char *lc_messages = NULL;
146-
#ifdef USE_ICU
147-
static char locale_provider = COLLPROVIDER_ICU;
148-
#else
149146
static char locale_provider = COLLPROVIDER_LIBC;
150-
#endif
151147
static char *icu_locale = NULL;
152148
static char *icu_rules = NULL;
153149
static const char *default_text_search_config = NULL;
@@ -2357,19 +2353,6 @@ icu_validate_locale(const char *loc_str)
23572353
#endif
23582354
}
23592355

2360-
/*
2361-
* Determine the default ICU locale
2362-
*/
2363-
static char *
2364-
default_icu_locale(void)
2365-
{
2366-
#ifdef USE_ICU
2367-
return pg_strdup(uloc_getDefault());
2368-
#else
2369-
pg_fatal("ICU is not supported in this build");
2370-
#endif
2371-
}
2372-
23732356
/*
23742357
* set up the locale variables
23752358
*
@@ -2429,10 +2412,7 @@ setlocales(void)
24292412

24302413
/* acquire default locale from the environment, if not specified */
24312414
if (icu_locale == NULL)
2432-
{
2433-
icu_locale = default_icu_locale();
2434-
printf(_("Using default ICU locale \"%s\".\n"), icu_locale);
2435-
}
2415+
pg_fatal("ICU locale must be specified");
24362416

24372417
/* canonicalize to a language tag */
24382418
langtag = icu_language_tag(icu_locale);
@@ -3273,7 +3253,6 @@ main(int argc, char *argv[])
32733253
break;
32743254
case 8:
32753255
locale = "C";
3276-
locale_provider = COLLPROVIDER_LIBC;
32773256
break;
32783257
case 9:
32793258
pwfilename = pg_strdup(optarg);

src/bin/initdb/t/001_initdb.pl

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103

104104
if ($ENV{with_icu} eq 'yes')
105105
{
106+
command_fails_like(
107+
[ 'initdb', '--no-sync', '--locale-provider=icu', "$tempdir/data2" ],
108+
qr/initdb: error: ICU locale must be specified/,
109+
'locale provider ICU requires --icu-locale');
110+
106111
command_ok(
107112
[
108113
'initdb', '--no-sync',

src/bin/pg_dump/t/002_pg_dump.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@
19651965
create_sql =>
19661966
"CREATE DATABASE dump_test2 LOCALE = 'C' TEMPLATE = template0;",
19671967
regexp => qr/^
1968-
\QCREATE DATABASE dump_test2 \E.*\QLOCALE = 'C'\E
1968+
\QCREATE DATABASE dump_test2 \E.*\QLOCALE = 'C';\E
19691969
/xm,
19701970
like => { pg_dumpall_dbprivs => 1, },
19711971
},

src/bin/scripts/t/020_createdb.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
program_options_handling_ok('createdb');
1414

1515
my $node = PostgreSQL::Test::Cluster->new('main');
16-
$node->init(extra => ['--locale-provider=libc']);
16+
$node->init;
1717
$node->start;
1818

1919
$node->issues_sql_like(

src/test/icu/t/010_database.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313

1414
my $node1 = PostgreSQL::Test::Cluster->new('node1');
15-
$node1->init(extra => ['--locale-provider=libc']);
15+
$node1->init;
1616
$node1->start;
1717

1818
$node1->safe_psql('postgres',

src/test/regress/expected/collate.icu.utf8.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1023,15 +1023,15 @@ SET client_min_messages TO WARNING;
10231023
do $$
10241024
BEGIN
10251025
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
1026-
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');';
1026+
quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
10271027
END
10281028
$$;
10291029
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
10301030
ERROR: collation "test0" already exists
10311031
do $$
10321032
BEGIN
10331033
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
1034-
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');';
1034+
quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
10351035
END
10361036
$$;
10371037
RESET client_min_messages;

src/test/regress/sql/collate.icu.utf8.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ SET client_min_messages TO WARNING;
362362
do $$
363363
BEGIN
364364
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
365-
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');';
365+
quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
366366
END
367367
$$;
368368
CREATE COLLATION test0 FROM "C"; -- fail, duplicate name
369369
do $$
370370
BEGIN
371371
EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' ||
372-
quote_literal((SELECT daticulocale FROM pg_database WHERE datname = current_database())) || ');';
372+
quote_literal((SELECT CASE WHEN datlocprovider='i' THEN daticulocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');';
373373
END
374374
$$;
375375

0 commit comments

Comments
 (0)