Re: BUG #7493: Postmaster messages are unreadable in a Windows console - Mailing list pgsql-bugs

From Alexander Law
Subject Re: BUG #7493: Postmaster messages are unreadable in a Windows console
Date
Msg-id 502A26F1.6010109@gmail.com
Whole thread Raw
In response to BUG #7493: Postmaster messages are unreadable in a Windows console  (exclusion@gmail.com)
List pgsql-bugs
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

Attachment

pgsql-bugs by date:

Previous
From: exclusion@gmail.com
Date:
Subject: BUG #7493: Postmaster messages are unreadable in a Windows console
Next
From: Rikard Pavelic
Date:
Subject: Re: BUG #7485: 9.2 beta3 libxml2 can't be loaded on Windows