CREATE DATABASE copies datlocale even if datlocprovider differs

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: CREATE DATABASE copies datlocale even if datlocprovider differs
Date: 2025-07-29 23:33:45
Message-ID: 5038b33a6dc639009f4b3d43fa6ae0c5ba9e04f7.camel@j-davis.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


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

Attachment Content-Type Size
0001-Do-not-copy-datlocale-unless-datlocprovider-matches.patch text/x-patch 1023 bytes

Browse pgsql-bugs by date

  From Date Subject
Next Message Samuel Marks 2025-07-30 03:01:16 Re: BUG #19002: `pg_isready` unexpectedly succeeds on incorrect `--dbname` and/or `--username`
Previous Message Jacob Champion 2025-07-29 19:54:43 Re: BUG #19002: `pg_isready` unexpectedly succeeds on incorrect `--dbname` and/or `--username`