Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZPP3C-00032G-FH for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Aug 2015 05:58:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZPP3B-0001sb-9e for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Aug 2015 05:58:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZPP2Z-00019a-5y for pgsql-bugs@postgresql.org; Wed, 12 Aug 2015 05:57:31 +0000 Received: from mail-pa0-x22b.google.com ([2607:f8b0:400e:c03::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZPP2U-0004ff-Ia for pgsql-bugs@postgresql.org; Wed, 12 Aug 2015 05:57:29 +0000 Received: by pabyb7 with SMTP id yb7so7134349pab.0 for ; Tue, 11 Aug 2015 22:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=IooTJJXmyaAjta2WUZYdytTiYggI19a3ictjGP55Qmc=; b=NNDvbJzfYrXreuF+7pxH4NuAV12JJfKqt6gfRhlHcTTfWhAZoWtwYvtXQ70DWLvj79 /X0s9JG2tOeAo+mrYf0MPoAWLNc1hQ5QmgzYBLQVXEb5F2NNeTHSbH8Nkm2K6q3PY3j2 VjIOXwfLmvODizBKwFqYGTiUfOw0WGUWNC3hs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=IooTJJXmyaAjta2WUZYdytTiYggI19a3ictjGP55Qmc=; b=CZBAgJ/zulkzYwAGndaQLpQ1bcBO0+YIrgC6vIBMiXmWU1/yrt8BpofvvYB4x9IQWZ QzHtxetoe/zM+DrAjsJ6qGwtU11Q7prWfHwJdJwGLcw+mf06rmJbrRG0rYCCLpUS2tCO Ny9B/AnVEQQsJnjZ8SQ7BofDhT3BLsjn0GTGyrXzYoM6vc9RPNgagH7F/5kQM2t6HzyT TVj9irWOFm6ObkXPLRKFYPwMA6nBJWQM4ixENcpDlAVyFUkjW9ya9IJ9HqVUmRQC8I9u lKpjTn4a+q0OW+eKdYzm7Y0igBBKyswORKYm51P/YCCgi+HUnEyPg40wqrKs6PJ42Kd8 Bbzw== X-Gm-Message-State: ALoCoQnCmvnOtVcz3XBD1VjOCMWkIy4dexK66Je5OscgYpYJxeL4/StkXhRrej14mV8TrTN1YMDg X-Received: by 10.66.155.102 with SMTP id vv6mr62827078pab.150.1439359042572; Tue, 11 Aug 2015 22:57:22 -0700 (PDT) Received: from tornado.leadboat.com (c-98-248-47-228.hsd1.ca.comcast.net. [98.248.47.228]) by smtp.gmail.com with ESMTPSA id nm8sm4870313pbc.20.2015.08.11.22.57.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Aug 2015 22:57:21 -0700 (PDT) Date: Wed, 12 Aug 2015 01:57:19 -0400 From: Noah Misch To: Dmitri.Bourlatchkov@software.dell.com Cc: pgsql-bugs@postgresql.org, tgl@sss.pgh.pa.us Subject: Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid Message-ID: <20150812055719.GA1945333@tornado.leadboat.com> References: <20150610143235.2796.52303@wrigleys.postgresql.org> <20150805033211.GA1768970@tornado.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Content-Disposition: inline In-Reply-To: <20150805033211.GA1768970@tornado.leadboat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Aug 04, 2015 at 11:32:11PM -0400, Noah Misch wrote: > On Wed, Jun 10, 2015 at 02:32:35PM +0000, Dmitri.Bourlatchkov@software.dell.com wrote: > > 4. Run postgresql.exe (no args) > > 5. Observe the following error message: > > > > ---- > > FATAL: XX000: cannot perform encoding conversion outside a transaction > > LOCATION: pg_do_encoding_conversion, src\backend\utils\mb\mbutils.c:360 > > ---- > Commit 49c817e is the proximate cause. On my Windows Server 2008 system, > Korean is the only locale affected. It's affected because pg_enc2name_tbl > lacks a UHC <-> CP949 mapping. I'll double check, but adding that mapping > should fix this particular test case. > > That leaves other ways of reaching this error. I think e.g. an LC_CTYPE=C, > ENCODING=LATIN9 database will still take this path. LATIN9 does not, but LATIN8 does. Plain 'make check' fails early in Korean locales, and 'make check EXTRA_REGRESS_OPTS="--encoding=LATIN8 --no-locale"' fails in any OS locale. > Any EmitErrorReport() can > run pgwin32_message_to_UTF16(), and those have plenty of ways to run outside a > transaction. I am inclined to restore the 9.3 and earlier semantics by having > pgwin32_message_to_UTF16() proceed, when outside a transaction, as though the > string is already UTF8. I am attaching the two patches I plan to use. Either one by itself fixes the symptom you observed. > A robust fix would be to cache enough information > about the message encoding to convert outside a transaction, exactly the way > we protect database<->client encoding conversions. That feels more like a > master-only change, though it's a borderline case. I propose to add this to https://wiki.postgresql.org/wiki/Todo: * Multi-Language Support ** Windows: Cache MessageEncoding conversion for use outside transactions Thanks, nm --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="to_UTF16-outside-xact-v1.patch" commit 48d9766 Author: Noah Misch AuthorDate: Wed Aug 12 01:42:53 2015 -0400 Commit: Noah Misch CommitDate: Wed Aug 12 01:42:53 2015 -0400 Restore old pgwin32_message_to_UTF16() behavior outside transactions. Commit 49c817eab78c6f0ce8c3bf46766b73d6cf3190b7 replaced with a hard error the dubious pg_do_encoding_conversion() behavior when outside a transaction. Reintroduce the historic soft failure locally within pgwin32_message_to_UTF16(). This fixes errors when writing messages in less-common encodings to the Windows event log or console. Back-patch to 9.4, where the aforementioned commit first appeared. Per bug #13427 from Dmitri Bourlatchkov. diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 1e9a004..2a8271a 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -1063,7 +1063,8 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len) /* * Use MultiByteToWideChar directly if there is a corresponding codepage, - * or double conversion through UTF8 if not. + * or double conversion through UTF8 if not. Double conversion is needed, + * for example, in an ENCODING=LATIN8, LC_CTYPE=C database. */ if (codepage != 0) { @@ -1075,12 +1076,21 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len) { char *utf8; - utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, - len, - GetMessageEncoding(), - PG_UTF8); - if (utf8 != str) - len = strlen(utf8); + /* + * XXX pg_do_encoding_conversion() requires a transaction. In the + * absence of one, hope for the input to be valid UTF8. + */ + if (IsTransactionState()) + { + utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, + len, + GetMessageEncoding(), + PG_UTF8); + if (utf8 != str) + len = strlen(utf8); + } + else + utf8 = (char *) str; utf16 = (WCHAR *) palloc(sizeof(WCHAR) * (len + 1)); dstlen = MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, len); --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="uhc-v1.patch" commit f20025b (HEAD) Author: Noah Misch AuthorDate: Wed Aug 12 01:43:17 2015 -0400 Commit: Noah Misch CommitDate: Wed Aug 12 01:43:17 2015 -0400 Encoding PG_UHC is code page 949. This fixes presentation of non-ASCII messages to the Windows event log and console in rare cases involving Korean locale. Processes like the postmaster and checkpointer, but not processes attached to databases, were affected. Back-patch to 9.4, where MessageEncoding was introduced. The problem exists in all supported versions, but this change has no effect in the absence of the code recognizing PG_UHC MessageEncoding. Noticed while investigating bug #13427 from Dmitri Bourlatchkov. diff --git a/src/backend/utils/mb/encnames.c b/src/backend/utils/mb/encnames.c index 94334c4..11099b8 100644 --- a/src/backend/utils/mb/encnames.c +++ b/src/backend/utils/mb/encnames.c @@ -344,7 +344,7 @@ const pg_enc2name pg_enc2name_tbl[] = DEF_ENC2NAME(SJIS, 932), DEF_ENC2NAME(BIG5, 950), DEF_ENC2NAME(GBK, 936), - DEF_ENC2NAME(UHC, 0), + DEF_ENC2NAME(UHC, 949), DEF_ENC2NAME(GB18030, 54936), DEF_ENC2NAME(JOHAB, 0), DEF_ENC2NAME(SHIFT_JIS_2004, 932) --nFreZHaLTZJo0R7j Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --nFreZHaLTZJo0R7j--