Bug 22592 - Encoding Problem beim Anlegen einer PSQL Datenbank
Encoding Problem beim Anlegen einer PSQL Datenbank
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: PostgreSQL
UCS 3.0
Other Linux
: P5 normal (vote)
: UCS 3.0 - MS2
Assigned To: Felix Botner
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-23 17:15 CEST by Felix Botner
Modified: 2011-12-13 15:51 CET (History)
3 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Botner univentionstaff 2011-05-23 17:15:48 CEST
Bei der Installation vom postgres werden zwei Template Datenbanken template0 und template1 angelegt. Diese dienen später als Vorlage für neue Datenbanken (standardmäßig wird beim Anlegen von Datenbanken wohl template1 als Vorlage verwendet).

In UCS 2.4 konnte man eine Datenbank aus template1 anlegen, auch wenn sich das encoding der beiden unterscheidet.

-> su - postgres -c "psql -c '\l'"
        Liste der Datenbanken
   Name    | Eigentümer | Kodierung 
-----------+-------------+-----------
 postgres  | postgres    | SQL_ASCII
 template0 | postgres    | SQL_ASCII
 template1 | postgres    | SQL_ASCII

-> su - postgres -c 'createdb  --encoding UNICODE testdb'

-> su - postgres -c "psql -c '\l'"
        Liste der Datenbanken
   Name    | Eigentümer | Kodierung 
-----------+-------------+-----------
 postgres  | postgres    | SQL_ASCII
 template0 | postgres    | SQL_ASCII
 template1 | postgres    | SQL_ASCII
 testdb    | postgres    | UTF8

In 3.0 scheint das so nicht mehr zu funktionieren. Hier erwartet postgres für die neuen Datenbank das gleiche encoding wie es template1 hat. Gibt man jedoch template0 als Vorlage an, funktioniert es auch mit einem anderen encoding.

-> su - postgres -c "psql -c '\l'"
                                  Liste der Datenbanken
   Name    | Eigentümer | Kodierung | Sortierfolge | Zeichentyp |  Zugriffsprivilegien  
-----------+-------------+-----------+--------------+------------+-----------------------
 postgres  | postgres    | SQL_ASCII | C            | C          | 
 template0 | postgres    | SQL_ASCII | C            | C          | =c/postgres
                                                                 : postgres=CTc/postgres
 template1 | postgres    | SQL_ASCII | C            | C          | =c/postgres
                                                                 : postgres=CTc/postgres

# ohne Angabe des Template (implizit template1) oder bei Verwendung von
# template1 gibt es folgende Fehlermeldung 
-> su - postgres -c 'createdb  --encoding UNICODE testdb'
createdb: Erzeugung der Datenbank ist fehlgeschlagen: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
TIP:  Use the same encoding as in the template database, or use template0 as template.

# mit template0 funktioniert es
-> su - postgres -c 'createdb -T template0 --encoding UNICODE testdb'

su - postgres -c "psql -c '\l'"
                                  Liste der Datenbanken
   Name    | Eigentümer | Kodierung | Sortierfolge | Zeichentyp |  Zugriffsprivilegien  
-----------+-------------+-----------+--------------+------------+-----------------------
 postgres  | postgres    | SQL_ASCII | C            | C          | 
 template0 | postgres    | SQL_ASCII | C            | C          | =c/postgres
                                                                 : postgres=CTc/postgres
 template1 | postgres    | SQL_ASCII | C            | C          | =c/postgres
                                                                 : postgres=CTc/postgres
 testdb    | postgres    | UTF8      | C            | C          | 

1. Was ist der Unterschied zw. template0 und template1
2. Warum funktioniert es in 2.4 ohne Probleme (postgres bug? in 3.0)

Wenn sich herausstellen sollte, das die Angabe von template0 um eine Datenbank mit einem anderen encoding anzulegen zwingende Voraussetzung ist, müssen wohl einige UCS Pakete angepasst werden (zumindest univention-printquotadb, univention-pkgdb)
Comment 1 Philipp Hahn univentionstaff 2011-05-24 07:49:03 CEST
(In reply to comment #0)
> 1. Was ist der Unterschied zw. template0 und template1

Siehe <http://www.postgresql.org/docs/8.4/interactive/manage-ag-templatedbs.html>:
Wie der Name vermuten lässt, handelt es sich bei "template0"  um eine leere-Datenbank, wohingegen "template1" als Standard-Vorlage für andere Datanbanken bereits einige Vorgaben enthält, z.B. dort die Verwendung von PL/pgSQL aktiviert ist. Damit enthält diese Datenbank bereits Daten in der angegebenen Kodierung, was dann nicht einfacht geändert werden kann.

Das Default-Encoding wird initial beim "initdb" angegeben, siehe <http://www.postgresql.org/docs/8.4/static/multibyte.html>. Danach kann es IMHO nur durch ein Dump+Restore verändert werden.
Comment 2 Felix Botner univentionstaff 2011-05-25 17:07:21 CEST
Hier gibt es wohl einen Unterschied zw. 8.3 und 8.4. In 8.3 kann man laut http://www.postgresql.org/docs/8.3/static/multibyte.html das Encoding beim Anlegen einer DB auch angeben wenn das (default) template1 verwendet wird. In 8.4 geht das laut http://www.postgresql.org/docs/8.4/static/multibyte.html nicht mehr. Hierbei ist nun zwingend die Angabe des template0 Voraussetzung:

CREATE DATABASE korean WITH ENCODING 'EUC_KR' LC_COLLATE='ko_KR.euckr' LC_CTYPE='ko_KR.euckr' TEMPLATE=template0;

createdb -E EUC_KR -T template0 --lc-collate=ko_KR.euckr --lc-ctype=ko_KR.euckr korean

Das heisst, wir müssen unsere Pakete, die PSQL Datenbanken anlegen, dahingehend prüfen.

Mir fallen das spontan folgende ein:

   * univention-printquotadb (pykota) -> Bug #22149
   * univention-pkgdb -> an diesem Bug

ein
Comment 3 Felix Botner univentionstaff 2011-06-03 07:50:56 CEST
univention-pkgdb angepasst. Dort wird beim Anlegen der Datenbank nun template0 als Vorlagen angegeben.

QA.

1) Testen ob sich univention-pkgdb (UNICODE) auch auf einem System installieren läßt, dessen Postgres Datenbanken ein ASCII (oder anderes) Encoding haben. Dafür sollte vor der Installation von univention-postgresql die default locale auf ungleich UTF8 gestellt werden:

-> ucr get locale/default
C

-> apt-get install univention-postgresql
-> su -c "psql -c '\l'" postgres
                              List of databases
   Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges   
-----------+----------+-----------+-----------+-------+-----------------------
 postgres  | postgres | SQL_ASCII | C         | C     | 
 template0 | postgres | SQL_ASCII | C         | C     | =c/postgres ...
 template1 | postgres | SQL_ASCII | C         | C     | =c/postgres ...

-> apt-get install univention-pkgdb

-> su -c "psql -c '\l'" postgres
                              List of databases
   Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges   
-----------+----------+-----------+-----------+-------+-----------------------
 pkgdb     | pkgdbu   | UTF8      | C         | C     | =Tc/pkgdbu ...
 postgres  | postgres | SQL_ASCII | C         | C     | 
 template0 | postgres | SQL_ASCII | C         | C     | =c/postgres ...
 template1 | postgres | SQL_ASCII | C         | C     | =c/postgres ...
(5 rows)

2) Gibt es noch mehr Pakete, die eine PSQL Datenbank anlegen wollen, dabei explizit ein Encoding vorgeben aber nicht template0 verwenden?
Comment 4 Andreas Büsching univentionstaff 2011-09-29 17:28:32 CEST
(In reply to comment #3)
> 1) Testen ob sich univention-pkgdb (UNICODE) auch auf einem System installieren
> läßt, dessen Postgres Datenbanken ein ASCII (oder anderes) Encoding haben.
> Dafür sollte vor der Installation von univention-postgresql die default locale
> auf ungleich UTF8 gestellt werden:

Funktioniert.
 
> -> apt-get install univention-pkgdb

Funktioniert auch
 
ChangeLog vorhanden
Comment 5 Sönke Schwardt-Krummrich univentionstaff 2011-12-13 15:51:20 CET
UCS 3.0-0 wurde veröffentlicht. Sollte der hier beschriebene Bug mit einer
neueren Version von UCS erneut auftreten, so sollte dieser Bug dupliziert
werden: "Clone This Bug"