Re: DROP COLLATION vs pg_collation question

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: DROP COLLATION vs pg_collation question
Date: 2024-06-18 14:44:23
Message-ID: 30eb1a5a-794c-4ee6-b305-9bdaaa9e56ff@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/18/24 06:32, Karsten Hilbert wrote:
> Am Tue, Jun 18, 2024 at 03:02:56PM +0200 schrieb Karsten Hilbert:
>
>> I see, and since any database can be used as a template for
>> more databases, which can be create with an encoding
>> different from the template,
>
> Proving myself wrong:
>
>
> root(at)hermes:~/tmp# sudo -u postgres psql -e -f /tmp/db.sql
> Output format is wrapped.
> drop database if exists new_tmpl;
> DROP DATABASE
> create database new_tmpl with encoding = 'utf8';
> CREATE DATABASE
> You are now connected to database "new_tmpl" as user "postgres".
> select current_database();
> current_database
> ------------------
> new_tmpl
> (1 row)
>
> drop database if exists new_latin1;
> psql:/tmp/db.sql:8: HINWEIS: Datenbank »new_latin1« existiert nicht, wird übersprungen
> DROP DATABASE
> create database new_latin1 with template = new_tmpl encoding = 'latin1' locale = 'de_DE(at)latin1';
> psql:/tmp/db.sql:9: FEHLER: neue Kodierung (LATIN1) ist inkompatibel mit der Kodierung der Template-Datenbank (UTF8)
> TIP: Verwenden Sie die gleiche Kodierung wie die Template-Datenbank oder verwenden Sie template0 als Template.

That is covered here:

https://www.postgresql.org/docs/16/manage-ag-templatedbs.html

"Another common reason for copying template0 instead of template1 is
that new encoding and locale settings can be specified when copying
template0, whereas a copy of template1 must use the same settings it
does. This is because template1 might contain encoding-specific or
locale-specific data, while template0 is known not to."

Substitute <db_name other then template0> for template1 and you can get
the error you received.

>
> Karsten
> --
> GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message HORDER Philip 2024-06-18 14:59:16 RE: Restore of a reference database kills the auto analyze processing.
Previous Message Alvaro Herrera 2024-06-18 14:43:40 Re: How to attach partition with primary key