From 54637508f87bd5f07fb9406bac6b08240283be3b Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 27 Jan 2022 08:44:31 +0100 Subject: Change collate and ctype fields to type text This changes the data type of the catalog fields datcollate, datctype, collcollate, and collctype from name to text. There wasn't ever a really good reason for them to be of type name; presumably this was just carried over from when they were fixed-size fields in pg_control, first into the corresponding pg_database fields, and then to pg_collation. The values are not identifiers or object names, and we don't ever look them up that way. Changing to type text saves space in the typical case, since locale names are typically only a few bytes long. But it is also possible that an ICU locale name with several customization options appended could be longer than 63 bytes, so this also enables that case, which was previously probably broken. Reviewed-by: Julien Rouhaud Discussion: https://www.postgresql.org/message-id/flat/5e756dd6-0e91-d778-96fd-b1bcb06c161a@2ndquadrant.com --- src/backend/utils/init/postinit.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/init/postinit.c') diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 0236165f60f..d046caabd7d 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -53,6 +53,7 @@ #include "storage/sync.h" #include "tcop/tcopprot.h" #include "utils/acl.h" +#include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/guc.h" #include "utils/memutils.h" @@ -306,6 +307,8 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect { HeapTuple tup; Form_pg_database dbform; + Datum datum; + bool isnull; char *collate; char *ctype; @@ -389,8 +392,12 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT); /* assign locale variables */ - collate = NameStr(dbform->datcollate); - ctype = NameStr(dbform->datctype); + datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datcollate, &isnull); + Assert(!isnull); + collate = TextDatumGetCString(datum); + datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datctype, &isnull); + Assert(!isnull); + ctype = TextDatumGetCString(datum); if (pg_perm_setlocale(LC_COLLATE, collate) == NULL) ereport(FATAL, -- cgit v1.2.3