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

Commit d5ac14f

Browse files
committed
Use libc version as a collation version on glibc systems.
Using glibc's version string to detect potential collation definition changes is not 100% reliable, but it's better than nothing. Currently this affects only collations explicitly provided by "libc". More work will be needed to handle the default collation. Author: Thomas Munro, based on a suggestion from Christoph Berg Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/4b76c6d4-ae5e-0dc6-7d0d-b5c796a07e34%402ndquadrant.com
1 parent 4351142 commit d5ac14f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

doc/src/sgml/ref/alter_collation.sgml

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ HINT: Rebuild all objects affected by this collation and run ALTER COLLATION pg
129129
does not actually check whether all affected objects have been rebuilt
130130
correctly.
131131
</para>
132+
<para>
133+
When using collations provided by <literal>libc</literal> and
134+
<productname>PostgreSQL</productname> was built with the GNU C library, the
135+
C library's version is used as a collation version. Since collation
136+
definitions typically change only with GNU C library releases, this provides
137+
some defense against corruption, but it is not completely reliable.
138+
</para>
139+
<para>
140+
Currently, there is no version tracking for the database default collation.
141+
</para>
132142

133143
<para>
134144
The following query can be used to identify all collations in the current

src/backend/utils/adt/pg_locale.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
#include <unicode/ucnv.h>
7171
#endif
7272

73+
#ifdef __GLIBC__
74+
#include <gnu/libc-version.h>
75+
#endif
76+
7377
#ifdef WIN32
7478
/*
7579
* This Windows file defines StrNCpy. We don't need it here, so we undefine
@@ -1499,7 +1503,7 @@ pg_newlocale_from_collation(Oid collid)
14991503
char *
15001504
get_collation_actual_version(char collprovider, const char *collcollate)
15011505
{
1502-
char *collversion;
1506+
char *collversion = NULL;
15031507

15041508
#ifdef USE_ICU
15051509
if (collprovider == COLLPROVIDER_ICU)
@@ -1523,7 +1527,13 @@ get_collation_actual_version(char collprovider, const char *collcollate)
15231527
}
15241528
else
15251529
#endif
1526-
collversion = NULL;
1530+
if (collprovider == COLLPROVIDER_LIBC)
1531+
{
1532+
#if defined(__GLIBC__)
1533+
/* Use the glibc version because we don't have anything better. */
1534+
collversion = pstrdup(gnu_get_libc_version());
1535+
#endif
1536+
}
15271537

15281538
return collversion;
15291539
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,8 @@
13761376
'CREATE COLLATION test0 FROM "C"' => {
13771377
create_order => 76,
13781378
create_sql => 'CREATE COLLATION test0 FROM "C";',
1379-
regexp => qr/^
1380-
\QCREATE COLLATION public.test0 (provider = libc, locale = 'C');\E/xm,
1379+
regexp =>
1380+
qr/CREATE COLLATION public.test0 \(provider = libc, locale = 'C'(, version = '[^']*')?\);/m,
13811381
collation => 1,
13821382
like => { %full_runs, section_pre_data => 1, },
13831383
},

0 commit comments

Comments
 (0)