Thread: Encoding problems with "COMMENT ON DATABASE .." causing pg_restore (and pg_upgrade) to fail

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
Ctype       |   Access privileges
--------------------+-----------+-----------+------------------+---------=
---------+-----------------------
  comment_test       | postgres  | UTF8      | C                | C      =
=20
          |
  [...]
  postgres           | postgres  | SQL_ASCII | C                | C      =
=20
          |
  template0          | postgres  | SQL_ASCII | C                | C      =
=20
          | =3Dc/postgres          +
                     |           |           |                  |        =
=20
          | postgres=3DCTc/postgres
  template1          | postgres  | SQL_ASCII | C                | C      =
=20
          | postgres=3DCTc/postgres+
                     |           |           |                  |        =
=20
          | =3Dc/postgres
SSBhbSBub3QgZmFtaWxpYXIgd2l0aCBwZ2FkbWluMyBidXQgaXQgc2VlbXMgYSBidWcgd2l0aCBw
Z2FkbWluMyBvcg0KbWl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NRTF9BU0NJSSB8IEMgfCBDIHwgcG9zdGdyZXM9Q1Rj
L3Bvc3RncmVzKw0KPiAgICAgICAgICAgICAgICAgICAgIHwgfCB8IHwgfCA9Yy9wb3N0Z3Jlcw0K
PiANCj4gDQo+IC0tIA0KPiBTZW50IHZpYSBwZ3NxbC1idWdzIG1haWxpbmcgbGlzdCAocGdzcWwt
YnVnc0Bwb3N0Z3Jlc3FsLm9yZykNCj4gVG8gbWFrZSBjaGFuZ2VzIHRvIHlvdXIgc3Vic2NyaXB0
aW9uOg0KPiBodHRwOi8vd3d3LnBvc3RncmVzcWwub3JnL21haWxwcmVmL3Bnc3FsLWJ1Z3MNCg==
Am 2016-01-27 01:45, schrieb Tatsuo Ishii:
> I am not familiar with pgadmin3 but it seems a bug with pgadmin3 or
> misuse of it to me. Probably when this:
>=20
>> ---> use pgadmin3 on Windows to set comment on database coment_test=20
>> with
>> ---> string "f=C3=BCr", while being connected to postgres (SQL_ASCII=20
>> encoded)
>=20
> was executed, the client encoding is not properly set to UTF-8 for
> some reasons.

I think you are actually right. It seems this only happens if you=20
initially connect to a SQL_ASCII databse with pgadmin3 and then set a=20
comment containing special characters on a UTF-8 database. I could now=20
also reproduce this behaviour on a Linux host with Postgre 9.4.5.
And I can also confirm that this does not happen using psql.

I will forward this issue to the pgadmin mailing list.

Thanks and best regards

Jan
On Wed, Jan 27, 2016 at 08:44:27AM +0100, Jan Lentfer wrote:
> Am 2016-01-27 01:45, schrieb Tatsuo Ishii:
> >I am not familiar with pgadmin3 but it seems a bug with pgadmin3 or
> >misuse of it to me. Probably when this:
> >
> >>---> use pgadmin3 on Windows to set comment on database
> >>coment_test with
> >>---> string "für", while being connected to postgres (SQL_ASCII
> >>encoded)
> >
> >was executed, the client encoding is not properly set to UTF-8 for
> >some reasons.
>
> I think you are actually right. It seems this only happens if you
> initially connect to a SQL_ASCII databse with pgadmin3 and then set
> a comment containing special characters on a UTF-8 database. I could
> now also reproduce this behaviour on a Linux host with Postgre
> 9.4.5.
> And I can also confirm that this does not happen using psql.
>
> I will forward this issue to the pgadmin mailing list.

I see no one else commented on this.  We have trouble keeping the global
system catalogs consistent when databases in the same cluster use
different encodings.  I am not sure how we could improve this.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription                             +
On 2/16/16 10:38 AM, Bruce Momjian wrote:
> I see no one else commented on this.  We have trouble keeping the global
> system catalogs consistent when databases in the same cluster use
> different encodings.  I am not sure how we could improve this.

Could we force the global catalogs to always be accessed via UTF8, at
least for modification? I suspect that would mean changing encodings on
the fly in the appropriate command functions (such as what's listed in
src/include/commands/user.h).
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
On Tue, Feb 16, 2016 at 01:36:24PM -0600, Jim Nasby wrote:
> On 2/16/16 10:38 AM, Bruce Momjian wrote:
> >I see no one else commented on this.  We have trouble keeping the global
> >system catalogs consistent when databases in the same cluster use
> >different encodings.  I am not sure how we could improve this.
>
> Could we force the global catalogs to always be accessed via UTF8,
> at least for modification? I suspect that would mean changing
> encodings on the fly in the appropriate command functions (such as
> what's listed in src/include/commands/user.h).

I don't remember us favoring UTF8 in this way in the past.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription                             +
On 2/16/2016 12:06 PM, Bruce Momjian wrote:
> On Tue, Feb 16, 2016 at 01:36:24PM -0600, Jim Nasby wrote:
>> >On 2/16/16 10:38 AM, Bruce Momjian wrote:
>>> > >I see no one else commented on this.  We have trouble keeping the global
>>> > >system catalogs consistent when databases in the same cluster use
>>> > >different encodings.  I am not sure how we could improve this.
>> >
>> >Could we force the global catalogs to always be accessed via UTF8,
>> >at least for modification? I suspect that would mean changing
>> >encodings on the fly in the appropriate command functions (such as
>> >what's listed in src/include/commands/user.h).
> I don't remember us favoring UTF8 in this way in the past.

what encoding SHOULD the global catalogs be in when the databases are in
different encodings?   I'm not sure there's any answer better than utf8 ?

--
john r pierce, recycling bits in santa cruz
On 2/16/16 2:10 PM, John R Pierce wrote:
>>> >Could we force the global catalogs to always be accessed via UTF8,
>>> >at least for modification? I suspect that would mean changing
>>> >encodings on the fly in the appropriate command functions (such as
>>> >what's listed in src/include/commands/user.h).
>> I don't remember us favoring UTF8 in this way in the past.
>
> what encoding SHOULD the global catalogs be in when the databases are in
> different encodings?   I'm not sure there's any answer better than utf8 ?

You could probably make an argument for SQL_ASCII.

The part about all of this that concerns me is what happens when people
query global catalogs directly... I'm not sure if we have the ability to
force specific conversions when that happens.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
Bruce Momjian <bruce@momjian.us> writes:
> On Tue, Feb 16, 2016 at 01:36:24PM -0600, Jim Nasby wrote:
>> Could we force the global catalogs to always be accessed via UTF8,
>> at least for modification? I suspect that would mean changing
>> encodings on the fly in the appropriate command functions (such as
>> what's listed in src/include/commands/user.h).

> I don't remember us favoring UTF8 in this way in the past.

Yeah.  I'm pretty sure the Far Eastern contingent has specifically lobbied
against giving UTF8 such a preference.  Also, if a name in the shared
catalog is UTF8, what do you do when it cannot be converted to the local
database encoding?  I don't think pretending the entry isn't there will do.

Perhaps a reasonable thing for now is to document that it's a bad idea
to put non-ASCII characters in names or comments of shared objects
(databases, roles, tablespaces) unless all databases of the cluster share
the same encoding.  I don't know if it would be useful/practical to try
to mechanically enforce such a rule, but we could at least warn people
about the issue.

            regards, tom lane
> I see no one else commented on this.  We have trouble keeping the global
> system catalogs consistent when databases in the same cluster use
> different encodings.  I am not sure how we could improve this.

Long time ago I proposed an idea to solve this kind of problems:

http://www.postgresql.org/message-id/20131112.155752.666523035722474275.t-ishii@sraoss.co.jp

The implementation details are not necessarily the best but still I
believe what we need is "round trip encoding conversion safe"
universal encoding for internal use.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp