pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Law <exclusion@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #7493: Postmaster messages are unreadable in a Windows console
Date: Tue, 14 Aug 2012 14:22:41 +0400
Message-ID: <502A26F1.6010109@gmail.com> (raw)
In-Reply-To: <E1T1E7f-0000bG-R5@wrigleys.postgresql.org>
References: <E1T1E7f-0000bG-R5@wrigleys.postgresql.org>

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

Attachments:

main.patch (text/x-patch, 324B) download --- 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

view thread (2+ messages)

Message-ID: <502A26F1.6010109@gmail.com>
Permalink:  ../502A26F1.6010109@gmail.com/
Also on:    postgresql.org/message-id/502A26F1.6010109@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com
  Subject: Re: BUG #7493: Postmaster messages are unreadable in a Windows console
  In-Reply-To: <502A26F1.6010109@gmail.com>
  References: <E1T1E7f-0000bG-R5@wrigleys.postgresql.org> <502A26F1.6010109@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox