Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zlvjn-0005H8-5d for pgsql-jdbc@arkaria.postgresql.org; Tue, 13 Oct 2015 09:19:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zlvjm-0005kc-4y for pgsql-jdbc@arkaria.postgresql.org; Tue, 13 Oct 2015 09:19:14 +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 1ZlvjG-0005CV-RJ for pgsql-jdbc@postgresql.org; Tue, 13 Oct 2015 09:18:42 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZlvjD-0008A4-6b for pgsql-jdbc@postgresql.org; Tue, 13 Oct 2015 09:18:41 +0000 Received: by lbbck17 with SMTP id ck17so12363463lbb.1 for ; Tue, 13 Oct 2015 02:18:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=pUd5oUZfSvPxvtFLIpx3vJdxTtFyJnS81kl6sLv9R1o=; b=DUnsK1YaRgNLx2yUCSCDHjd5UsAsYtyyMfnNE86qalJqZUZP7VH2lIGGFoznIUTB8B 0lYDa3PHlxpbskEfCLI4A/4LrQYS8FzzyDVBa/TIkShcnhP24oJPHFsvY1xgoWAVKXmH NyCfBN02aNZjGJvrwgto7pNsmnlYhKpiNLWurkRiSyCUYys+o37KX7lPyZYT7ck6q/QX UNGZ1nLc+Sj3bpxstqXvHXJY43aXmbrJ3uhbbZWD6icGrUGZVuO638/uGN9YTaKzydT0 Sghyc8NGv5oHXoARmRMR7ruk3uN37STVSo3VrXViBhZMQyhOqwDqYZ6uYlKmWbXfvT7K ZlzA== X-Gm-Message-State: ALoCoQmApgvdKy29tMNJ4gQJQ3S/NgTtnf5L4puthkekddNdeb6M6IZFf/ZP6UI+IN3a+3ejDkdr X-Received: by 10.25.159.16 with SMTP id i16mr9547499lfe.63.1444727915725; Tue, 13 Oct 2015 02:18:35 -0700 (PDT) Received: from [192.168.1.132] (120.77.218.87.dynamic.jazztel.es. [87.218.77.120]) by smtp.googlemail.com with ESMTPSA id e13sm354257lfb.4.2015.10.13.02.18.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Oct 2015 02:18:34 -0700 (PDT) Message-ID: <561CCC69.8030306@8Kdata.com> Date: Tue, 13 Oct 2015 11:18:33 +0200 From: =?UTF-8?B?w4FsdmFybyBIZXJuw6FuZGV6IFRvcnRvc2E=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org, Chang Chao Subject: Re: UTF8 is a better option than US-ASCII for the default encoding of PGStream References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------010103010603050507080108" X-Pg-Spam-Score: -1.8 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. --------------010103010603050507080108 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 13/10/15 10:04, Chang Chao wrote: > After some googling,found that the same issue was already discussed > before. > http://postgresql.nabble.com/JDBC-Default-Encoding-td2172427.html > So to prevent the error message text garbling,we have to change the > value of lc_messages from 'ja_JP.UTF-8' to "en_US.UTF8"? Hi Chang! Based on http://www.postgresql.org/message-id/4678.1438350389@sss.pgh.pa.us, what I'd say is that the best thing to do should be to send *in the startup message*: - client_encoding: desired client encoding - lc_messages: C and encode the startup message in US_ASCII (lowest common denominator). And of course switch the encoding of further messages if server replies (ParameterStatus) with a different encoding (which should happen if we sent in StartupMessage a different encoding request). Hope this helps. Cheers, Álvaro -- Álvaro Hernández Tortosa ----------- 8Kdata > > On Tue, Oct 13, 2015 at 4:48 PM, Chang Chao > wrote: > > Hi,all > The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' > is set in postgresql.conf,and initial connection to database > server failed(for example:user name,password or dbname is > misspelled),I see garbled error message text in the client .The > reason is that,in PGStream constrcutor,default encoding of ASCII > is set(Encoding.getJVMEncoding("US-ASCII")).For the following > reasons,maybe UTF8 is a better option for default encoding. > > 1.When initializing connection ,jdbcclient send client_encoding > parameter as UTF-8 > see > org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[], > String, String, Properties, Logger) > > 2. When initial connection to server completes,jdbc client only > receive the value for client_encoding as UTF-8 > see > org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream, > ProtocolConnectionImpl, Logger) > > if (name.equals("client_encoding")) > { > if (!value.equals("UTF8")) > throw new PSQLException(GT.tr("Protocol error. Session setup > failed."), PSQLState.PROTOCOL_VIOLATION); > pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8")); > } > > So there seems no reason to initiate the encoding as US-ASCII. > > Best regards. > Chao. > > --------------010103010603050507080108 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 13/10/15 10:04, Chang Chao wrote:
After some googling,found that the same issue was already discussed before.
http://postgresql.nabble.com/JDBC-Default-Encoding-td2172427.html
So to prevent the error message text garbling,we have to change the value of lc_messages from  'ja_JP.UTF-8' to "en_US.UTF8"?

    Hi Chang!

    Based on http://www.postgresql.org/message-id/4678.1438350389@sss.pgh.pa.us, what I'd say is that the best thing to do should be to send *in the startup message*:

- client_encoding:    desired client encoding
- lc_messages: C

    and encode the startup message in US_ASCII (lowest common denominator). And of course switch the encoding of further messages if server replies (ParameterStatus) with a different encoding (which should happen if we sent in StartupMessage a different encoding request).

    Hope this helps. Cheers,

    Álvaro

-- 
Álvaro Hernández Tortosa


-----------
8Kdata




On Tue, Oct 13, 2015 at 4:48 PM, Chang Chao <charleschung.cn@gmail.com> wrote:
Hi,all
The problem I encountered is that,when lc_messages = 'ja_JP.UTF-8' is set in postgresql.conf,and initial connection to database server failed(for example:user name,password or dbname is misspelled),I see garbled error message text in the client .The reason is that,in PGStream constrcutor,default encoding of ASCII is set(Encoding.getJVMEncoding("US-ASCII")).For the following reasons,maybe UTF8 is a better option for default encoding.

1.When initializing connection ,jdbcclient send client_encoding parameter as UTF-8
 see org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(HostSpec[], String, String, Properties, Logger)

2. When initial connection to server completes,jdbc client only receive the value for client_encoding as UTF-8 
 see org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(PGStream, ProtocolConnectionImpl, Logger)

if (name.equals("client_encoding"))
                {
                    if (!value.equals("UTF8"))
                        throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
                    pgStream.setEncoding(Encoding.getDatabaseEncoding("UTF8"));
                }

So there seems no reason to initiate the encoding as US-ASCII.

Best regards.
Chao.


--------------010103010603050507080108--