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
--- 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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs