Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U88LO-0005Ny-R0 for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Feb 2013 12:00:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U88LO-00027D-6H for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Feb 2013 12:00:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U88LM-00026c-NG for pgsql-hackers@postgresql.org; Wed, 20 Feb 2013 12:00:12 +0000 Received: from mail-la0-x236.google.com ([2a00:1450:4010:c03::236]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U88LF-0008Sn-9X for pgsql-hackers@postgresql.org; Wed, 20 Feb 2013 12:00:11 +0000 Received: by mail-la0-f54.google.com with SMTP id gw10so7437598lab.41 for ; Wed, 20 Feb 2013 04:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type; bh=k1LqDCY4DFop6NvTBwzqKiefDrgU4quJLdQzYTn9PnQ=; b=BNUwMY/AHNCFymrqXBaaaJSvr5aTzZw7X3AiH+TfuVAIA1IFtLQzwpQxjN2H2t6paE f4O5PYhvYI3REaJ7ctjgRh0yRbyxn6Ort5cgVueyUUKXoZ62PKc21dCXI6HYCOwKkoLN PtcqpUebOB8MjYO9tYQsFNVfoqLRIdfA8aOPI56BsOaaceWrOJI2Rh4kLCczTOeUjjwN j5Z3CB7NQ9AQCeE66EltTh/D7cwWCZFsbASqtjF4LvO4Q/DnKd7GI29ZMcdD7paG+mHE JBsqDUU6AG5TXyKyZcFLvzSp3pWnmJzNRZJ+jMuewzIaTUzqKst/yJIZoVUxiWl02zB9 Rb6g== X-Received: by 10.152.112.231 with SMTP id it7mr16666663lab.10.1361361604589; Wed, 20 Feb 2013 04:00:04 -0800 (PST) Received: from [1.0.0.7] ([94.138.23.211]) by mx.google.com with ESMTPS id e9sm23069445lbz.1.2013.02.20.04.00.01 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Feb 2013 04:00:02 -0800 (PST) Message-ID: <5124BAC0.4060006@gmail.com> Date: Wed, 20 Feb 2013 16:00:00 +0400 From: Alexander Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: Noah Misch CC: Tom Lane , pgsql-hackers , Magnus Hagander , Andrew Dunstan Subject: Re: BUG #7493: Postmaster messages unreadable in a Windows console References: <5100F3F6.3050107@2ndQuadrant.com> <51013C2C.5020703@dunslane.net> <20130124161954.GA2448@tornado.leadboat.com> <5101A1C4.3020407@dunslane.net> <5107656C.1050400@gmail.com> <28316.1359471244@sss.pgh.pa.us> <20130130015155.GD3524@tornado.leadboat.com> <5108B6E1.9070503@gmail.com> <20130210210259.GA7401@tornado.leadboat.com> <511C8E11.7090407@gmail.com> <20130214225957.GA5626@tornado.leadboat.com> In-Reply-To: <20130214225957.GA5626@tornado.leadboat.com> Content-Type: multipart/mixed; boundary="------------000706000903060804090305" X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------000706000903060804090305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, 15.02.2013 02:59, Noah Misch wrote: >>> With your proposed change, the problem will resurface in an actual SQL_ASCII >>> database. At the problem's root is write_console()'s assumption that messages >>> are in the database encoding. pg_bind_textdomain_codeset() tries to make that >>> so, but it only works for encodings with a pg_enc2gettext_tbl entry. That >>> excludes SQL_ASCII, MULE_INTERNAL, and others. write_console() needs to >>> behave differently in such cases. >> Thank you for the notice. So it seems that "DatabaseEncoding" variable >> alone can't present a database encoding (for communication with a >> client) and current process messages encoding (for logging messages) at >> once. There should be another variable, something like >> CurrentProcessEncoding, that will be set to OS encoding at start and can >> be changed to encoding of a connected database (if >> bind_textdomain_codeset succeeded). > I'd call it MessageEncoding unless it corresponds with similar rigor to a > broader concept. Please look at the next version of the patch. Thanks, Alexander --------------000706000903060804090305 Content-Type: text/x-patch; name="0001-Fix-postmaster-messages-encoding.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-postmaster-messages-encoding.patch" From 5bce21326d48761c6f86be8797432a69b2533dcd Mon Sep 17 00:00:00 2001 From: Alexander Lakhin Date: Wed, 20 Feb 2013 15:34:05 +0400 Subject: Fix postmaster messages encoding --- src/backend/main/main.c | 2 ++ src/backend/utils/error/elog.c | 4 ++-- src/backend/utils/mb/mbutils.c | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 1173bda..ed4067e 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -100,6 +100,8 @@ main(int argc, char *argv[]) set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); + SetMessageEncoding(GetPlatformEncoding()); + #ifdef WIN32 /* diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 3a211bf..40f20f3 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -1868,7 +1868,7 @@ write_eventlog(int level, const char *line, int len) * Also verify that we are not on our way into error recursion trouble due * to error messages thrown deep inside pgwin32_toUTF16(). */ - if (GetDatabaseEncoding() != GetPlatformEncoding() && + if (GetMessageEncoding() != GetPlatformEncoding() && !in_error_recursion_trouble()) { utf16 = pgwin32_toUTF16(line, len, NULL); @@ -1915,7 +1915,7 @@ write_console(const char *line, int len) * through to writing unconverted if we have not yet set up * CurrentMemoryContext. */ - if (GetDatabaseEncoding() != GetPlatformEncoding() && + if (GetMessageEncoding() != GetPlatformEncoding() && !in_error_recursion_trouble() && !redirection_done && CurrentMemoryContext != NULL) diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 287ff80..8b51b78 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -57,6 +57,7 @@ static FmgrInfo *ToClientConvProc = NULL; */ static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; +static pg_enc2name *MessageEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; static pg_enc2name *PlatformEncoding = NULL; /* @@ -881,6 +882,16 @@ SetDatabaseEncoding(int encoding) Assert(DatabaseEncoding->encoding == encoding); } +void +SetMessageEncoding(int encoding) +{ + if (!PG_VALID_BE_ENCODING(encoding)) + elog(ERROR, "invalid message encoding: %d", encoding); + + MessageEncoding = &pg_enc2name_tbl[encoding]; + Assert(MessageEncoding->encoding == encoding); +} + /* * Bind gettext to the codeset equivalent with the database encoding. */ @@ -915,6 +926,8 @@ pg_bind_textdomain_codeset(const char *domainname) if (bind_textdomain_codeset(domainname, pg_enc2gettext_tbl[i].name) == NULL) elog(LOG, "bind_textdomain_codeset failed"); + else + SetMessageEncoding(encoding); break; } } @@ -964,6 +977,13 @@ GetPlatformEncoding(void) return PlatformEncoding->encoding; } +int +GetMessageEncoding(void) +{ + Assert(MessageEncoding); + return MessageEncoding->encoding; +} + #ifdef WIN32 /* @@ -977,7 +997,7 @@ pgwin32_toUTF16(const char *str, int len, int *utf16len) int dstlen; UINT codepage; - codepage = pg_enc2name_tbl[GetDatabaseEncoding()].codepage; + codepage = pg_enc2name_tbl[GetMessageEncoding()].codepage; /* * Use MultiByteToWideChar directly if there is a corresponding codepage, @@ -994,7 +1014,7 @@ pgwin32_toUTF16(const char *str, int len, int *utf16len) char *utf8; utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, - len, GetDatabaseEncoding(), PG_UTF8); + len, GetMessageEncoding(), PG_UTF8); if (utf8 != str) len = strlen(utf8); -- 1.7.10.4 --------------000706000903060804090305 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------000706000903060804090305--