Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b13b2a

Browse files
committed
Rethink behavior of pg_import_system_collations().
Marco Atzeri reported that initdb would fail if "locale -a" reportedthe same locale name more than once. All previous versions of Postgresimplicitly de-duplicated the results of "locale -a", but the rewriteto move the collation import logic into C had lost that property.It had also lost the property that locale names matching built-incollation names were silently ignored.The simplest way to fix this is to make initdb run the function inif-not-exists mode, which means that there's no real use-case fornon if-not-exists mode; we might as well just drop the boolean argumentand simplify the function's definition to be "add any collations notalready known". This change also gets rid of some odd corner casescaused by the fact that aliases were added in if-not-exists mode evenif the function argument said otherwise.While at it, adjust the behavior so that pg_import_system_collations()doesn't spew "collation foo already exists, skipping" messages during are-run; that's completely unhelpful, especially since there are oftenhundreds of them. And make it return a count of the number of collationsit did add, which seems like it might be helpful.Also, re-integrate the previous coding's property that it would make adeterministic selection of which alias to use if there were conflictingpossibilities. This would only come into play if "locale -a" reportsmultiple equivalent locale names, say "de_DE.utf8" and "de_DE.UTF-8",but that hardly seems out of the question.In passing, fix incorrect behavior in pg_import_system_collations()'sICU code path: it neglected CommandCounterIncrement, which would resultin failures if ICU returns duplicate names, and it would try to createcomments even if a new collation hadn't been created.Also, reorder operations in initdb so that the 'ucs_basic' collationis created before calling pg_import_system_collations() not after.This prevents a failure if "locale -a" were to report a locale namedthat. There's no reason to think that that ever happens in the wild,but the old coding would have survived it, so let's be equally robust.Discussion:https://postgr.es/m/20c74bc3-d6ca-243d-1bbc-12f17fa4fe9a@gmail.com
1 parent9ea3c64 commit0b13b2a

File tree

7 files changed

+254
-138
lines changed

7 files changed

+254
-138
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19711,9 +19711,9 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
1971119711
<row>
1971219712
<entry>
1971319713
<indexterm><primary>pg_import_system_collations</primary></indexterm>
19714-
<literal><function>pg_import_system_collations(<parameter>if_not_exists</> <type>boolean</>, <parameter>schema</> <type>regnamespace</>)</function></literal>
19714+
<literal><function>pg_import_system_collations(<parameter>schema</> <type>regnamespace</>)</function></literal>
1971519715
</entry>
19716-
<entry><type>void</type></entry>
19716+
<entry><type>integer</type></entry>
1971719717
<entry>Import operating system collations</entry>
1971819718
</row>
1971919719
</tbody>
@@ -19730,18 +19730,20 @@ postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
1973019730
</para>
1973119731

1973219732
<para>
19733-
<function>pg_import_system_collations</>populates the system
19734-
catalog <literal>pg_collation</literal>with collationsbased on all the
19735-
locales it findson the operating system. This is
19733+
<function>pg_import_system_collations</>adds collations to the system
19734+
catalog <literal>pg_collation</literal> based on all the
19735+
locales it findsin the operating system. This is
1973619736
what <command>initdb</command> uses;
1973719737
see <xref linkend="collation-managing"> for more details. If additional
1973819738
locales are installed into the operating system later on, this function
19739-
can be run again to add collations for the new locales. In that case, the
19740-
parameter <parameter>if_not_exists</parameter> should be set to true to
19741-
skip over existing collations. The <parameter>schema</parameter>
19742-
parameter would typically be <literal>pg_catalog</literal>, but that is
19743-
not a requirement. (Collation objects based on locales that are no longer
19744-
present on the operating system are never removed by this function.)
19739+
can be run again to add collations for the new locales. Locales that
19740+
match existing entries in <literal>pg_collation</literal> will be skipped.
19741+
(But collation objects based on locales that are no longer
19742+
present in the operating system are not removed by this function.)
19743+
The <parameter>schema</parameter> parameter would typically
19744+
be <literal>pg_catalog</literal>, but that is not a requirement;
19745+
the collations could be installed into some other schema as well.
19746+
The function returns the number of new collation objects it created.
1974519747
</para>
1974619748

1974719749
</sect2>

‎src/backend/catalog/pg_collation.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
* CollationCreate
3838
*
3939
* Add a new tuple to pg_collation.
40+
*
41+
* if_not_exists: if true, don't fail on duplicate name, just print a notice
42+
* and return InvalidOid.
43+
* quiet: if true, don't fail on duplicate name, just silently return
44+
* InvalidOid (overrides if_not_exists).
4045
*/
4146
Oid
4247
CollationCreate(constchar*collname,Oidcollnamespace,
@@ -45,7 +50,8 @@ CollationCreate(const char *collname, Oid collnamespace,
4550
int32collencoding,
4651
constchar*collcollate,constchar*collctype,
4752
constchar*collversion,
48-
boolif_not_exists)
53+
boolif_not_exists,
54+
boolquiet)
4955
{
5056
Relationrel;
5157
TupleDesctupDesc;
@@ -77,7 +83,9 @@ CollationCreate(const char *collname, Oid collnamespace,
7783
Int32GetDatum(collencoding),
7884
ObjectIdGetDatum(collnamespace)))
7985
{
80-
if (if_not_exists)
86+
if (quiet)
87+
returnInvalidOid;
88+
elseif (if_not_exists)
8189
{
8290
ereport(NOTICE,
8391
(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -119,7 +127,12 @@ CollationCreate(const char *collname, Oid collnamespace,
119127
Int32GetDatum(-1),
120128
ObjectIdGetDatum(collnamespace))))
121129
{
122-
if (if_not_exists)
130+
if (quiet)
131+
{
132+
heap_close(rel,NoLock);
133+
returnInvalidOid;
134+
}
135+
elseif (if_not_exists)
123136
{
124137
heap_close(rel,NoLock);
125138
ereport(NOTICE,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp