From: Noah Misch <noah@leadboat.com>
To: Dmitri.Bourlatchkov@software.dell.com
Cc: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
Date: Wed, 12 Aug 2015 01:57:19 -0400
Message-ID: <20150812055719.GA1945333@tornado.leadboat.com> (raw)
In-Reply-To: <20150805033211.GA1768970@tornado.leadboat.com>
References: <20150610143235.2796.52303@wrigleys.postgresql.org>
<20150805033211.GA1768970@tornado.leadboat.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:download all (2 files, .tar.gz)to_UTF16-outside-xact-v1.patch (text/plain, 2.1K) download
commit 48d9766
Author: Noah Misch <noah@leadboat.com>
AuthorDate: Wed Aug 12 01:42:53 2015 -0400
Commit: Noah Misch <noah@leadboat.com>
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.cindex 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);
uhc-v1.patch (text/plain, 1.2K) download
commit f20025b (HEAD)
Author: Noah Misch <noah@leadboat.com>
AuthorDate: Wed Aug 12 01:43:17 2015 -0400
Commit: Noah Misch <noah@leadboat.com>
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.cindex 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noah@leadboat.com, Dmitri.Bourlatchkov@software.dell.com, tgl@sss.pgh.pa.us
Subject: Re: BUG #13427: postgres.exe fails to start on Korean Windows Server 2008: cannot perform encoding conversion outsid
In-Reply-To: <20150812055719.GA1945333@tornado.leadboat.com>
References: <20150610143235.2796.52303@wrigleys.postgresql.org> <20150805033211.GA1768970@tornado.leadboat.com> <20150812055719.GA1945333@tornado.leadboat.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox