Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8qT0-0003U1-Hy for pgsql-general@arkaria.postgresql.org; Tue, 26 Mar 2019 18:06:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8qSy-0004Bm-VH for pgsql-general@arkaria.postgresql.org; Tue, 26 Mar 2019 18:06:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8qSy-0004Az-EG for pgsql-general@lists.postgresql.org; Tue, 26 Mar 2019 18:06:28 +0000 Received: from sonic303-3.consmr.mail.bf2.yahoo.com ([74.6.131.42]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8qSu-0007yv-TI for pgsql-general@lists.postgresql.org; Tue, 26 Mar 2019 18:06:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1553623582; bh=P2ZXLbMXxHx0lBMgbBlK5xoriq82hmAVHHFNb8uHqFI=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=kg+SsFqROB9bb6adwcE1BOTtKHSSgmt3zD9FkRwdlVM2uyWNWRhuTrXkSmpn8M+Iy2NBcCVwLSZQm0Rp04Rr+7fX/96nc0TJaA5wl3iy3yPDhzNUD8P8LKexRZB2BXGBbN2goUroca7Lp18jLjmNrf8R1s8YmBCXDV3piVX2NlIMVg7bkursQPAHqI7GJQQ8SlLqJ+StMu3A+SYJpLF5fUeNcYeg9KhVa59idUsiul8LWhujsk2mF3wioxRagpvD8UCaeA69N37Zjo64/0fEvUve09qULU13mq4b+k8lC77bzZ8tYSUYfBl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fczbxKL3.pqaTbNSe5seFcZYWRR Y.6uQ6glYbWRcr8d8CUnmEFx83T_lC3vf38.kCYYl9jEDgttsHqKbvwj1dOTAWrthQfGRGMJWnDl eZAK6ysuS8LCRMijJUeWwLFiZtufpIdJKWmi3ln1mAKlEzuiE2ODme9r2nA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Tue, 26 Mar 2019 18:06:22 +0000 Date: Tue, 26 Mar 2019 18:06:15 +0000 (UTC) From: Thomas Tignor To: Brad Nicholson , Tom Lane Cc: "pgsql-general@lists.postgresql.org" , Vijaykumar Jain Message-ID: <1013768132.11403739.1553623575830@mail.yahoo.com> In-Reply-To: <18058.1553609672@sss.pgh.pa.us> References: <1080815989.10741938.1553539577631.ref@mail.yahoo.com> <1080815989.10741938.1553539577631@mail.yahoo.com> <458346306.10942574.1553559949857@mail.yahoo.com> <18058.1553609672@sss.pgh.pa.us> Subject: Re: [External] postgres 9.5 DB corruption: invalid byte sequence for encoding "UTF8" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11403738_441850259.1553623575828" X-Mailer: WebService/1.1.13212 YMailNorrin Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36 Content-Length: 10653 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_11403738_441850259.1553623575828 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello again Brad, and hello Tom. Thanks for writing, and Tom I'll add some = extra thanks for the many google searches over the years which have been an= swered by your posts. :) It seems there's been some confusion on the data flow so I'll try to explai= n. The original "source" I referred to was our JVM generating alert data an= d performing DML on the DB via the v42.0.0 driver. I do not know of any enc= oding setting for the driver itself. The driver writes directly to our primary (Slony-I master) DB. Changes are = then replicated by our replica (Slony-I subscriber) DBs. Each of these DBs = has a "UTF8" server encoding. COPY out ops (performed by Slony-I or anythin= g else) always work fine, and COPY in ops fail if there is data corruption. ams@ams3.dfw.netmgmt:/a/ams/lib/ext/database$ sum postgresql-42.0.0.jar=C2= =A0 12476 =C2=A0 691 ams@ams3.dfw.netmgmt:/a/ams/lib/ext/database$=C2=A0 ams@ams3.dfw.netmgmt:~$ echo ---- Slony-I Master ---- ---- Slony-I Master ---- ams@ams3.dfw.netmgmt:~$ psql -U akamai -d ams -c "SELECT datname, pg_encodi= ng_to_char(encoding) FROM pg_database WHERE datname =3D 'ams'" =C2=A0datname | pg_encoding_to_char=C2=A0 ---------+--------------------- =C2=A0ams =C2=A0 =C2=A0 | UTF8 (1 row) ams@ams3.dfw.netmgmt:~$=C2=A0 root@ams-repl7.sjc.netmgmt:~# echo ---- Slony-I Replica ---- ---- Slony-I Replica ---- root@ams-repl7.sjc.netmgmt:~# psql -U akamai -d ams -c "SELECT datname, pg_= encoding_to_char(encoding) FROM pg_database WHERE datname =3D 'ams'" =C2=A0datname | pg_encoding_to_char=C2=A0 ---------+--------------------- =C2=A0ams =C2=A0 =C2=A0 | UTF8 (1 row) root@ams-repl7.sjc.netmgmt:~#=C2=A0 Tom =C2=A0 =C2=A0:-)=20 On Tuesday, March 26, 2019, 10:14:59 AM EDT, Tom Lane wrote: =20 =20 "Brad Nicholson" writes: > Thomas Tignor wrote on 03/25/2019 08:25:49 PM: >> Thanks for writing. As I mentioned to Vijay, the "source" is a JVM >> using the postgres v42.0.0 JDBC driver. I do not believe we have any >> explicit encoding set, and so I expect the client encoding is >> SQL_ASCII. The DB is most definitely UTF8. > These statements are contradictory. > The value of client_encoding from your select on pg_settings is SQL_ASCII= . > The docs clearly state: > https://www.postgresql.org/docs/9.5/runtime-config-client.html > "Sets the client-side encoding (character set). The default is to use the > database encoding. " > If you don't have client_encoding explicitly, then it is using the databa= se > encoding. Umm ... not necessarily.=C2=A0 That bit in runtime-config-client.html correctly states what the *server's* default for client_encoding is, but an awful lot of client-side code will immediately override that. psql will try to set it based on its LANG/LC_CTYPE environment, for example.=C2=A0 I don't know what JDBC does; it might be different. But in any case, yes, it'd be more reliable to check pg_database.encoding explicitly. =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 regards, tom lane =20 ------=_Part_11403738_441850259.1553623575828 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello again Brad, and hello Tom. Thanks for writing, and Tom I= 'll add some extra thanks for the many google searches over the years which= have been answered by your posts. :)

It seems the= re's been some confusion on the data flow so I'll try to explain. The origi= nal "source" I referred to was our JVM generating alert data and performing= DML on the DB via the v42.0.0 driver. I do not know of any encoding settin= g for the driver itself.

The driver writes directl= y to our primary (Slony-I master) DB. Changes are then replicated by our re= plica (Slony-I subscriber) DBs. Each of these DBs has a "UTF8" server encod= ing. COPY out ops (performed by Slony-I or anything else) always work fine,= and COPY in ops fail if there is data corruption.

ams@ams3.dfw.netmg= mt:/a/ams/lib/ext/database$ sum postgresql-42.0.0.jar 

12476   691

ams@ams3.dfw.netmg= mt:/a/ams/lib/ext/database$ 

ams@ams3.dfw.netmg= mt:~$ echo ---- Slony-I Master ----

---- Slony-I Maste= r ----

ams@ams3.dfw.netmg= mt:~$ psql -U akamai -d ams -c "SELECT datname, pg_encoding_to_char(encodin= g) FROM pg_database WHERE datname =3D 'ams'"

 datname | pg_encoding_to_char 

---------+--------= -------------

 ams     | UTF8

(1 row)


ams@ams3.dfw.netmg= mt:~$ <= /p>

root@ams-repl7.sjc= .netmgmt:~# echo ---- Slony-I Replica ----

---- Slony-I Repli= ca ----

root@ams-repl7.sjc= .netmgmt:~# psql -U akamai -d ams -c "SELECT datname, pg_encoding_to_char(e= ncoding) FROM pg_database WHERE datname =3D 'ams'"

 datname | pg_encoding_to_char 

---------+--------= -------------

 ams     | UTF8

(1 row)


root@ams-repl7.sjc= .netmgmt:~# 



Tom    :-)


=20
=20
On Tuesday, March 26, 2019, 10:14:59 AM EDT, Tom Lane &= lt;tgl@sss.pgh.pa.us> wrote:


"Brad Nicholson" <bradn= @ca.ibm.com> writes:
> Thomas Tignor <tptignor@yahoo.com> wrote on 03/25/2019 08:25:49 PM:
>> Thanks for writing. As I mentioned to Vijay, the "source= " is a JVM
>> using the postgres v42.0.0 JDBC drive= r. I do not believe we have any
>> explicit encodin= g set, and so I expect the client encoding is
>> SQ= L_ASCII. The DB is most definitely UTF8.

> These statements are contradictory.

> The value of client_encoding from your select on pg_settings is = SQL_ASCII.

> The docs clearly state= :
> = https://www.postgresql.org/docs/9.5/runtime-config-client.html
> "Sets the client-side encoding (character set). The default = is to use the
> database encoding. "

> If you don't have client_encoding explicitly, then= it is using the database
> encoding.

Umm ... not necessarily.  That bit in runtime-con= fig-client.html
correctly states what the *server's* defa= ult for client_encoding is,
but an awful lot of client-si= de code will immediately override that.
psql will try to = set it based on its LANG/LC_CTYPE environment,
for exampl= e.  I don't know what JDBC does; it might be different.

But in any case, yes, it'd be more reliable to check= pg_database.encoding

explicitly.


            rega= rds, tom lane


------=_Part_11403738_441850259.1553623575828--