Thread: Encoding of early PG messages

Encoding of early PG messages

From
Shay Rojansky
Date:
Hi hackers.

Developing Npgsql I've encountered the problem described in http://www.postgresql.org/message-id/20081223212414.GD3894@merkur.hilbert.loc: a German installation of PostgreSQL seems to respond to an incorrect password with a non-UTF8 encoding of the error messages, even if the startup message contains client_encoding=UTF8.

It seems that the aforementioned thread didn't lead to a fix (either to respect client_encoding even for early messages, or to switch to ASCII English errors for these messages). Am I missing something here or is this the current situation in PG? Any plans for some sort of fix?

I can work around this by using "relaxed" decoding (i.e. not failing on non-UTF8 characters) but this means that error messages are partially or totally garbled...

Thanks,

Shay

Re: Encoding of early PG messages

From
Tom Lane
Date:
Shay Rojansky <roji@roji.org> writes:
> Developing Npgsql I've encountered the problem described in
> http://www.postgresql.org/message-id/20081223212414.GD3894@merkur.hilbert.loc:
> a German installation of PostgreSQL seems to respond to an incorrect
> password with a non-UTF8 encoding of the error messages, even if the
> startup message contains client_encoding=UTF8.

I wouldn't hold your breath waiting for that to change.

A possible workaround is to run the postmaster with lc_messages=C and
then switch to your desired message language per-session.  It would
certainly work to send lc_messages along with client_encoding in the
startup packet; or possibly you could set those settings as per-database
or per-role settings to avoid needing to teach the application code
about it.  This would mean that bad-password and similar errors would
come out in English, but at least they'd be validly encoded ...
        regards, tom lane



Re: Encoding of early PG messages

From
Shay Rojansky
Date:
Thanks for the suggestions Tom.

As I'm developing a general-purpose driver I can't do anything in PostgreSQL config, but it's a good workaround suggestion for users who encounter this error.

Sending lc_messages in the startup packet could work, but if I understand correctly that setting combines both encoding and language. I guess I can look at the user's locale preference on the client machine, try to translate that into a PostgreSQL language/encoding and send that in lc_messages - that seems like it might work.

Shay

On Fri, Jul 31, 2015 at 3:46 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Shay Rojansky <roji@roji.org> writes:
> Developing Npgsql I've encountered the problem described in
> http://www.postgresql.org/message-id/20081223212414.GD3894@merkur.hilbert.loc:
> a German installation of PostgreSQL seems to respond to an incorrect
> password with a non-UTF8 encoding of the error messages, even if the
> startup message contains client_encoding=UTF8.

I wouldn't hold your breath waiting for that to change.

A possible workaround is to run the postmaster with lc_messages=C and
then switch to your desired message language per-session.  It would
certainly work to send lc_messages along with client_encoding in the
startup packet; or possibly you could set those settings as per-database
or per-role settings to avoid needing to teach the application code
about it.  This would mean that bad-password and similar errors would
come out in English, but at least they'd be validly encoded ...

                        regards, tom lane

Re: Encoding of early PG messages

From
Shay Rojansky
Date:
Oh sorry, I think I misunderstood your suggestion - setting lc_messages in the startup packet wouldn't work any more than setting client_encoding, would it. So any solution here would be on the database/backend side, and so irrelevant for a general-purpose driver...

On Fri, Jul 31, 2015 at 4:28 PM, Shay Rojansky <roji@roji.org> wrote:
Thanks for the suggestions Tom.

As I'm developing a general-purpose driver I can't do anything in PostgreSQL config, but it's a good workaround suggestion for users who encounter this error.

Sending lc_messages in the startup packet could work, but if I understand correctly that setting combines both encoding and language. I guess I can look at the user's locale preference on the client machine, try to translate that into a PostgreSQL language/encoding and send that in lc_messages - that seems like it might work.

Shay


On Fri, Jul 31, 2015 at 3:46 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Shay Rojansky <roji@roji.org> writes:
> Developing Npgsql I've encountered the problem described in
> http://www.postgresql.org/message-id/20081223212414.GD3894@merkur.hilbert.loc:
> a German installation of PostgreSQL seems to respond to an incorrect
> password with a non-UTF8 encoding of the error messages, even if the
> startup message contains client_encoding=UTF8.

I wouldn't hold your breath waiting for that to change.

A possible workaround is to run the postmaster with lc_messages=C and
then switch to your desired message language per-session.  It would
certainly work to send lc_messages along with client_encoding in the
startup packet; or possibly you could set those settings as per-database
or per-role settings to avoid needing to teach the application code
about it.  This would mean that bad-password and similar errors would
come out in English, but at least they'd be validly encoded ...

                        regards, tom lane