Re: BUG #7493: Postmaster messages are unreadable in a Windows console

From: Alexander Law <exclusion(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7493: Postmaster messages are unreadable in a Windows console
Date: 2012-08-14 10:22:41
Message-ID: 502A26F1.6010109@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
main.patch text/x-patch 325 bytes

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Hiroshi Saito 2012-08-14 12:59:22 Re: Fwd: [BUGS] Small bug in psqlodbc-09.01 prevents interoperability with LISTSERV
Previous Message exclusion 2012-08-14 10:13:15 BUG #7493: Postmaster messages are unreadable in a Windows console