Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1EGr-0003X2-V8 for pgsql-bugs@postgresql.org; Tue, 14 Aug 2012 10:22:46 +0000 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1EGq-0006Vc-1I for pgsql-bugs@postgresql.org; Tue, 14 Aug 2012 10:22:45 +0000 Received: by lagy9 with SMTP id y9so110265lag.19 for ; Tue, 14 Aug 2012 03:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=AHiVL6K50TuKJsNlupXVfjlK525SqvUDKTuuOnCcq0w=; b=mxM3czsXN5LAIKDpRbdWikLToeLPbRMyqJSLuulJCOn2I8HMn3bOrXpg0C48YA2fFD 61/5YoevB4BVrgp3YsQ08HGXayQfdxRx3Y7kXz8Iy1N8kRSFtV9SM/UsvvZSDbIGCB6j PitiRP56oLyBnOBNK6GIeRagTl87IxcP6zMHBxAWpxAQCJa3LGlwgNzbLkwU9X4fYWk2 HKSUhzFLQ9j3rg0qt44PhJXovzyXaDoUYEFZvQh1Pv91fi05XbZpDN/VWxRupcgSk85A FmO6rmZVdZx1gGctkdmXlm+NewVO4+hP49l+BEDKOpOporz6p/n1LJxZrwqI7OmlHwpL q2tQ== Received: by 10.112.27.226 with SMTP id w2mr7817599lbg.57.1344939762956; Tue, 14 Aug 2012 03:22:42 -0700 (PDT) Received: from [1.0.0.7] ([94.138.26.200]) by mx.google.com with ESMTPS id mq9sm2009786lab.0.2012.08.14.03.22.40 (version=SSLv3 cipher=OTHER); Tue, 14 Aug 2012 03:22:41 -0700 (PDT) Message-ID: <502A26F1.6010109@gmail.com> Date: Tue, 14 Aug 2012 14:22:41 +0400 From: Alexander Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #7493: Postmaster messages are unreadable in a Windows console References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------050608020309050407070704" X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201208/78 X-Sequence-Number: 33802 This is a multi-part message in MIME format. --------------050608020309050407070704 Content-Type: multipart/alternative; boundary="------------060004060502000608090800" --------------060004060502000608090800 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello, while trying to set consistent log encoding (following the discussion http://archives.postgresql.org/message-id/5006D340.4000808%40gmail.com), I discovered a few bugs, that IMHO should be fixed before. > When I disable logging collector and try to run postmaster in a command > line, I get no readable text (I see only ASCII symbols). > > Please look at the screenshot. > http://oi45.tinypic.com/2ywy5o9.jpg I believe the problem is related to elog.c/write_console. Following encoding check can be found there: if (GetDatabaseEncoding() != GetPlatformEncoding() … and later, in mbutils.c/pgwin32_toUTF16 codepage = pg_enc2name_tbl[GetDatabaseEncoding()].codepage; So DatabaseEncoding here is an encoding of the current process messages (current encoding). Indeed, when the process connects to a database in postinit.c/CheckMyDatabase function it calls SetDatabaseEncoding(dbform->encoding); and then /* Use the right encoding in translated messages */ #ifdef ENABLE_NLS pg_bind_textdomain_codeset(textdomain(NULL)); #endif where the DatabaseEncoding is used again: int encoding = GetDatabaseEncoding(); So when a database connected, the process messages encoding is the database encoding. But until then DatabaseEncoding->encoding == 0 (PG_SQL_ASCII). However, translated messages are not ASCII-encoded. man bind_textdomain_codeset tells: "By default, the *gettext* family of functions returns translated messages in the locale's character encoding, which can be retrieved as *nl_langinfo(CODESET)*." So if DatabaseEncoding can (and should) be used as current process messages encoding, then until a database is connected it should be set to PlatformEncoding. I would suggest to add SetDatabaseEncoding(GetPlatformEncoding()); just before set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); in main.c, so it would reflect the same behavior as in postinit.c/CheckMyDatabase. I tested the patch on Windows and it works. Best regards, Alexander --------------060004060502000608090800 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello,
while trying to set consistent log encoding (following the discussion http://archives.postgresql.org/message-id/5006D340.4000808%40gmail.com), I discovered a few bugs, that IMHO should be fixed before.
When I disable logging collector and try to run postmaster in a command
line, I get no readable text (I see only ASCII symbols).

Please look at the screenshot.
http://oi45.tinypic.com/2ywy5o9.jpg

I believe the problem is related to elog.c/write_console. Following encoding check can be found there:
if (GetDatabaseEncoding() != GetPlatformEncoding() …
and later, in mbutils.c/pgwin32_toUTF16
codepage = pg_enc2name_tbl[GetDatabaseEncoding()].codepage;

So DatabaseEncoding here is an encoding of the current process messages (current encoding). Indeed, when the process connects to a database in postinit.c/CheckMyDatabase function it calls SetDatabaseEncoding(dbform->encoding); and then

/* Use the right encoding in translated messages */
#ifdef ENABLE_NLS
    pg_bind_textdomain_codeset(textdomain(NULL));
#endif
where the DatabaseEncoding is used again:
int encoding = GetDatabaseEncoding();


So when a database connected, the process messages encoding is the database encoding. But until then DatabaseEncoding->encoding == 0 (PG_SQL_ASCII). However, translated messages are not ASCII-encoded. man bind_textdomain_codeset tells:
"By default, the gettext family of functions returns translated messages in the locale's character encoding, which can be retrieved as nl_langinfo(CODESET)."
So if DatabaseEncoding can (and should) be used as current process messages encoding, then until a database is connected it should be set to PlatformEncoding.
I would suggest to add
SetDatabaseEncoding(GetPlatformEncoding());
just before  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); in main.c, so it would reflect the same behavior as in  postinit.c/CheckMyDatabase.
I tested the patch on Windows and it works.

Best regards,
Alexander
--------------060004060502000608090800-- --------------050608020309050407070704 Content-Type: text/x-patch; name="main.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="main.patch" --- D:\src\main.c 2012-08-13 11:56:48.000000000 +0400 +++ D:\src\postgresql\src\backend\main\main.c 2012-08-14 13:56:19.938905100 +0400 @@ -98,6 +98,8 @@ * error messages to be localized. */ + SetDatabaseEncoding(GetPlatformEncoding()); + set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); #ifdef WIN32 --------------050608020309050407070704--