Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gDBB9-0007Bh-Dd for pgsql-general@arkaria.postgresql.org; Thu, 18 Oct 2018 16:29:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gDBB7-0005UL-9j for pgsql-general@arkaria.postgresql.org; Thu, 18 Oct 2018 16:29:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gDBB6-0005UE-Tk for pgsql-general@lists.postgresql.org; Thu, 18 Oct 2018 16:29:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gDBB4-0004xG-4P for pgsql-general@lists.postgresql.org; Thu, 18 Oct 2018 16:29:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w9IGTXbV029518; Thu, 18 Oct 2018 12:29:34 -0400 From: Tom Lane To: =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= cc: pgsql-general@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG: Incorrect working with POSIX locale if database in UTF-8 encoding In-reply-to: <13FE0F7C-5140-499C-8C2E-0BE64BC3A48B@ya.ru> References: <13FE0F7C-5140-499C-8C2E-0BE64BC3A48B@ya.ru> Comments: In-reply-to =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= message dated "Wed, 17 Oct 2018 12:29:52 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29516.1539880173.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 18 Oct 2018 12:29:33 -0400 Message-ID: <29517.1539880173@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg=3D=3D?=3D wr= ites: > [ postmaster's localized messages are printed as garbage if LANG is C or= unset ] I'm not quite convinced that this is a bug. The reason it's misbehaving is that in the postmaster process (and, probably, non-backend children) LC_MESSAGES gets set to whatever you said in postgresql.conf, but LC_CTYPE is never changed away from what it was in the postmaster's environment. So if the prevailing environment setting is C/POSIX, gettext() throws up its hands and substitutes "?" for non-ASCII characters, because it has no idea which encoding to render them in. This is sort of intentional, in that the environment LC_CTYPE ought to reflect the "console encoding" that you're operating in; if you run your terminal in say KOI8R, then you set LC_CTYPE=3Dru_RU.koi8r and messages should get printed in the encoding the terminal is expecting. We could maybe make a case for forcing gettext to use the encoding implied by LC_MESSAGES if LC_CTYPE is C/POSIX, but I'm not really convinced that there's anything principled about that. On the other hand, the current behavior in this situation surely isn't useful to anybody. Arguably, gettext() is being pretty unhelpful here, but I doubt we could get them to change. Peter, any thoughts? regards, tom lane