Re: pg_upgrade doesn't copy ICU rules on template0

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: shihao zhong <zhong950419(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bohyun Lee <bohyun(dot)lee(at)databricks(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_upgrade doesn't copy ICU rules on template0
Date: 2026-10-31 10:15:56
Message-ID: c97d5993-5d9f-4f75-97f1-7e69643e37c0@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 29/10/2026 03:43, shihao zhong wrote:
>> Uh ... say what? template0 is supposed to be immutable after initdb.
>> I think the actual problem here is with whatever patch introduced
>> the possibility of this value changing.
>
> Users can't change template0 after initdb. The value changes inside
> pg_upgrade. Since 16, set_locale_and_encoding() copies the old
> template0's locale fields into the new template0 (9637badd9f9). That
> way the new cluster doesn't need the same initdb options. It misses
> daticurules.

Right. We surely should treat daticurules the same as encoding and
collation here.

Stepping back a bit though, what is the point of having any of these --
encoding, datcollate, datctype, daticurules -- set on template0? The
only thing you can do with template0 is to use it as template with
CREATE DATABASE, and you can override all of those values at that point.
So they just act as a default, when you use CREATE DATABASE. But a very
inflexible default at that, since you cannot change them after initdb.

I also noticed this:

First initialize cluster with --icu-rules:

initdb --icu-rules='rulez' --locale-provider='icu' --icu-locale=fi

Now try to create a non-ICU database:

postgres=# create database foodb WITH template template0
LOCALE_PROVIDER='builtin';
ERROR: ICU rules cannot be specified unless locale provider is ICU

Ok, fair enough. But since the ICU rules are coming from the template,
how do I specify "no ICU rules"? This doesn't work:

postgres=# create database foodb WITH template template0
LOCALE_PROVIDER='builtin' ICU_RULES='';
ERROR: ICU rules cannot be specified unless locale provider is ICU

So if you specify "initdb --icu-rules", you cannot create databases with
any other locale provider.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-10-31 10:42:10 Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti
Previous Message Kirill Reshke 2026-10-31 09:55:47 Re: ALTER COLLATION misses errcode