diff --git a/doc/src/sgml/ref/alter_collation.sgml b/doc/src/sgml/ref/alter_collation.sgml index b51b3a25647..4cfcb42251f 100644 --- a/doc/src/sgml/ref/alter_collation.sgml +++ b/doc/src/sgml/ref/alter_collation.sgml @@ -129,6 +129,16 @@ HINT: Rebuild all objects affected by this collation and run ALTER COLLATION pg does not actually check whether all affected objects have been rebuilt correctly. + + When using collations provided by libc and + PostgreSQL was built with the GNU C library, the + C library's version is used as a collation version. Since collation + definitions typically change only with GNU C library releases, this provides + some defense against corruption, but it is not completely reliable. + + + Currently, there is no version tracking for the database default collation. + The following query can be used to identify all collations in the current diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 2a076a3dfd1..fcdbaae37b9 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -70,6 +70,10 @@ #include #endif +#ifdef __GLIBC__ +#include +#endif + #ifdef WIN32 /* * This Windows file defines StrNCpy. We don't need it here, so we undefine @@ -1499,7 +1503,7 @@ pg_newlocale_from_collation(Oid collid) char * get_collation_actual_version(char collprovider, const char *collcollate) { - char *collversion; + char *collversion = NULL; #ifdef USE_ICU if (collprovider == COLLPROVIDER_ICU) @@ -1523,7 +1527,13 @@ get_collation_actual_version(char collprovider, const char *collcollate) } else #endif - collversion = NULL; + if (collprovider == COLLPROVIDER_LIBC) + { +#if defined(__GLIBC__) + /* Use the glibc version because we don't have anything better. */ + collversion = pstrdup(gnu_get_libc_version()); +#endif + } return collversion; } diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 4712e3a9581..11634204913 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -1376,8 +1376,8 @@ my %tests = ( 'CREATE COLLATION test0 FROM "C"' => { create_order => 76, create_sql => 'CREATE COLLATION test0 FROM "C";', - regexp => qr/^ - \QCREATE COLLATION public.test0 (provider = libc, locale = 'C');\E/xm, + regexp => + qr/CREATE COLLATION public.test0 \(provider = libc, locale = 'C'(, version = '[^']*')?\);/m, collation => 1, like => { %full_runs, section_pre_data => 1, }, },