Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aO5GB-0007LO-TG for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2016 15:10:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aO5GB-0002Bh-Bl for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2016 15:10:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aO5GA-0002BF-KY for pgsql-bugs@postgresql.org; Tue, 26 Jan 2016 15:10:22 +0000 Received: from mout.web.de ([212.227.17.11]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.84) (envelope-from ) id 1aO5G7-0007hx-J2 for pgsql-bugs@postgresql.org; Tue, 26 Jan 2016 15:10:21 +0000 Received: from vm-mailsrv.lan.net ([87.152.23.47]) by smtp.web.de (mrweb101) with ESMTPSA (Nemesis) id 0MYNrh-1ab84O0F97-00V99U for ; Tue, 26 Jan 2016 16:10:17 +0100 Received: from localhost (localhost [127.0.0.1]) by vm-mailsrv.lan.net (Postfix) with ESMTP id 2BE9E18817 for ; Tue, 26 Jan 2016 16:10:15 +0100 (CET) X-Spam-Flag: NO X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-0.999 tagged_above=-99.9 required=6.31 tests=[ALL_TRUSTED=-1, FREEMAIL_FROM=0.001] autolearn=unavailable autolearn_force=no Received: from vm-mailsrv.lan.net ([127.0.0.1]) by localhost (vm-mailsrv.lan.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rNCmMYTp7DEc for ; Tue, 26 Jan 2016 16:10:08 +0100 (CET) Received: from neslonek.homeunix.org (vm-webapp-ext.dmz-lan.net [192.168.0.100]) by vm-mailsrv.lan.net (Postfix) with ESMTP id 42B4918819 for ; Tue, 26 Jan 2016 16:10:01 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Date: Tue, 26 Jan 2016 16:10:01 +0100 From: Jan Lentfer To: pgsql-bugs@postgresql.org Subject: Encoding problems with "COMMENT ON DATABASE .." causing pg_restore (and pg_upgrade) to fail Message-ID: <666abab3fe03561c77dbfc661b023985@neslonek.homeunix.org> X-Sender: jan.lentfer@web.de User-Agent: Roundcube Webmail/1.1.4 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K0:rB2/4NS0ouzRHyCYiFzqeoapwpJHxnQvYu2I8NOUhTHMdGRFcEJ 1uVfmLEzFsLHV0xeCREGUuvajXm17nTlZNfGE0Fey+48FMv+phUcwdh5FzfXWTt8uNDV+xh wrzhth/qYrq/oE1f6QRFBC10TfndD8/cxd/oQz/MHD8aLUr0GSyYZExw5oHKUr6aEeW6BS0 FaGSBi3h4QF3MJJvjOgwg== X-UI-Out-Filterresults: notjunk:1;V01:K0:LU/9PGpV29c=:zNeBSjPVCPHvBGsYdkaNXh wRLugNP4Gp+ZoNJXiNGb60H2YXCQmi3UD9zVEA9+bFkNTYlHmvTUY7rOSDHa9HQM6V3F+Jbgt WmXrd2I60keVq7TCyS4eijf51e7b+xhETCTbHI71OL9k26aMzacDffNE5K67JpsVCoA2yZWwf PB9yWibBMp+N/WDwLUTJODJGJg8kBnnCBfGFma05PXMj2irGRvyltZV5Q8owiesUWI8vkYi53 P+3o0LeZbIp3PS7UdRkgCT++IniT+A7sGPWsOm2DhJph/LS+UHzjOn+5nZsFINzZbcwEU8P4e fhsIpnLuCGGu5JcoNA6BjWzRlg2YxpJxdiLi71xGnqOdt2JznA4tpJo0JlqkarzXtivJMNmQs 8nDxDO5rgqlqKCuvqKbW7kpVUsoIS0yq90PNeSoPyy3NlTbPpoO0/Zwt4b0NpiujmXnq7wnIK crYxNqAlcqA3jCHpejV9oHBU3c8pOkCL/GZnYjvZZzxvthy445tav9/ZYV1oquuNnDdIGUQKa A6xTfkyoiEhUYtEmMtRG0MISjF+Ca1obf2lJQDc5aMgqPLJmgCVwfbL+ArqMIw58kc8gGhSTK IT5q+KoZvm4gUvR2NAkG54fqAXEs3KX2XS2kFO04JrS11PnL7CjJXGwHA5srjddWwXaCwvNGa xyyZp/HkXdyaOuNq1ZxS1Wvm2/dMxql/tMAYvWZkLdf6OVadhjhJ5jX1A1uEbHmO5CPMw9gjK 9uBivbmyh25ED6KQY7evTqcPaO5o/m94tBOGmO7ETIGvR80YFg+CQfz5T4o7/wVv72053RiZI TS1hB7/ X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org We found a problem with comments on databases using german umlauts (=C3=A4= =C3=B6=C3=BC)=20 - or more generally, we found encoding problems when doing "COMMENT ON=20 database foo ..." when foo is UTF-8 encoded and the database you are=20 connected to (e.g. postgres) is SQL_ASCII. I analyzed this with the help of Andrew Gierth (and others) on IRC - it=20 seems in that constellation you can write an non-UTF-8 comment onto a=20 UTF-8 database. This leads to the problem, that wen trying to use pg_restore -C with a=20 dump created with -Fc the restore will fail when trying to do the=20 "COMMENT ON DATABASE.." We stumpled across this because also pg_upgrade fails on this (during=20 the schema part), but doesn't detect this situation with the -c (check)=20 option beforehand. This is 9.4.5 on Solaris 11 - but we did have that problem already when=20 using pg_upgrade from 8.4 to 9.1 a few years back. I am sorry we didn't=20 analyze further back then, but it was "just a comment". But now it bit=20 us again.... Here is what I did so far to analyze the problem (with instrucions from=20 Andrew Gierth). I hope this makes it clear, otherwise please don't=20 hesitate to request more details. postgres=3D# create database comment_test template template0 encoding=20 'UTF-8'; CREATE DATABASE ##### ---> use pgadmin3 on Windows to set comment on database coment_test with=20 string "f=C3=BCr", while being connected to postgres (SQL_ASCII encoded) ##### $ pg_dump -Fc comment_test -f comment_test.pgdump postgres=3D# alter database comment_test rename to comment_test_orig; ALTER DATABASE ##### $ pg_restore -C -d template1 comment_test.pgdump pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore: [archiver (db)] Error from TOC entry 1989; 1262 641528=20 COMMENT comment_test postgres pg_restore: [archiver (db)] could not execute query: ERROR: invalid=20 byte sequence for encoding "UTF8": 0xfc Command was: COMMENT ON DATABASE comment_test IS 'f=C2=A6r'; ### postgres@sz-pp-pg02-dev[~] $ pg_restore comment_test.pgdump -- -- PostgreSQL database dump -- SET statement_timeout =3D 0; SET lock_timeout =3D 0; SET client_encoding =3D 'UTF8'; SET standard_conforming_strings =3D on; SET check_function_bodies =3D false; SET client_min_messages =3D warning; -- -- Name: comment_test; Type: COMMENT; Schema: -; Owner: postgres -- COMMENT ON DATABASE comment_test IS 'f=C2=A6r'; -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; -- -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; -- -- Name: public; Type: ACL; Schema: -; Owner: postgres -- REVOKE ALL ON SCHEMA public FROM PUBLIC; REVOKE ALL ON SCHEMA public FROM postgres; GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO PUBLIC; -- -- PostgreSQL database dump complete -- ####### $ pg_restore comment_test.pgdump | head -16 | tail -1 |xxd 0000000: 434f 4d4d 454e 5420 4f4e 2044 4154 4142 COMMENT ON DATAB 0000010: 4153 4520 636f 6d6d 656e 745f 7465 7374 ASE comment_test 0000020: 2049 5320 2766 fc72 273b 0a IS 'f.r';. ###### postgres=3D# select=20 convert_to(shobj_description(oid,'pg_database'),'SQL_ASCII') from=20 pg_database where datname=3D'comment_test_orig'; convert_to ------------ \x66fc72 (1 row) ###### postgres=3D# \l List of databases Name | Owner | Encoding | Collate |=20=20=20= =20=20=20 Ctype | Access privileges --------------------+-----------+-----------+------------------+-----------= -------+----------------------- comment_test | postgres | UTF8 | C | C=20=20= =20=20=20=20=20 | [...] postgres | postgres | SQL_ASCII | C | C=20=20= =20=20=20=20=20 | template0 | postgres | SQL_ASCII | C | C=20=20= =20=20=20=20=20 | =3Dc/postgres + | | | |=20=20=20= =20=20=20=20=20=20 | postgres=3DCTc/postgres template1 | postgres | SQL_ASCII | C | C=20=20= =20=20=20=20=20 | postgres=3DCTc/postgres+ | | | |=20=20=20= =20=20=20=20=20=20 | =3Dc/postgres --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs