pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-bugs@postgresql.org
Subject: CREATE DATABASE copies datlocale even if datlocprovider differs
Date: Tue, 29 Jul 2025 16:33:45 -0700
Message-ID: <5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com> (raw)


  initdb -D data --locale-provider=builtin --builtin-locale='C.UTF-8'
  CREATE DATABASE d2 TEMPLATE template0 LOCALE_PROVIDER 'icu';
  WARNING:  ICU locale "C.UTF-8" has unknown language "c"
  HINT:  To disable ICU locale validation, set the parameter
"icu_validation_level" to "disabled".
  CREATE DATABASE

  SELECT datlocale FROM pg_database WHERE datname='d2';
   datlocale 
  -----------
   C.UTF-8
  (1 row)

It's only an issue if template0 is builtin and the new database is icu.
libc doesn't use the datlocale field, and the builtin provider will
reject ICU locale names. ICU is less strict for historical reasons.

I think that should throw an error rather than trying to reinterpret
datlocale for the new provider. Patch attached, intended to backport
through 17.

In theory that could break existing CREATE DATABASE commands, but given
that it's such a narrow case I don't think it's a major problem. We
could mitigate it by patching only 18+. Thoughts?

Regards,
	Jeff Davis

Attachments:

0001-Do-not-copy-datlocale-unless-datlocprovider-matches.patch (text/x-patch, 1023B) download From 7617f154b4c10e181eeeb949d773b5f1eee67954 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Tue, 29 Jul 2025 16:11:32 -0700 Subject: [PATCH] Do not copy datlocale unless datlocprovider matches. During CREATE DATABASE, if changing the locale provider, require that a new locale is specified rather than trying to reinterpret the old locale with the new provider. --- src/backend/commands/dbcommands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 502a45163c8..92a396b8406 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -1052,7 +1052,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt) dbctype = src_ctype; if (dblocprovider == '\0') dblocprovider = src_locprovider; - if (dblocale == NULL) + if (dblocale == NULL && dblocprovider == src_locprovider) dblocale = src_locale; if (dbicurules == NULL) dbicurules = src_icurules; -- 2.43.0

view thread (2+ messages)  latest in thread

Message-ID: <5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com>
Permalink:  ../5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com/
Also on:    postgresql.org/message-id/5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: pgsql@j-davis.com
  Subject: Re: CREATE DATABASE copies datlocale even if datlocprovider differs
  In-Reply-To: <5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox