Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Subject: Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding
Date: 2026-10-14 09:34:02
Message-ID: CAHGQGwHsAcbYiOHXu=_HZx=593ZgfX1+SzQDq8cib3OAAG7FCQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Oct 14, 2026 at 1:45 PM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
> Yes. glibc honors it too. On Ubuntu 24.04 with glibc 2.39,
> a ja_JP.UTF-8 locale and a UTF8 database, an unpatched psql 19 works,
> and with OUTPUT_CHARSET=EUC-JP it fails:
>
> ERROR: invalid byte sequence for encoding "UTF8": 0xc2 0xd0
>
> v4 uses the English label in that case.

Thanks for updating the patch!

With the v4 patch, I encountered another case that causes
an "ERROR: invalid byte sequence" error.

First, I started psql as follows:

$ OUTPUT_CHARSET=EUC-JP psql -X

When I ran \dn, the output was garbled because of the OUTPUT_CHARSET setting:

=# \dn
???????ް???
̾?? | \xBD?ͭ\xBC
--------+-------------------
public | pg_database_owner
(1 ??)

I then tried unsetting OUTPUT_CHARSET to address garbled output:

=# \setenv OUTPUT_CHARSET

Running \dn again resulted in an error:

=# \dn
ERROR: invalid byte sequence for encoding "UTF8": 0xc2 0xd0

This seems to happen because psql with the v4 patch sees the current
value of OUTPUT_CHARSET, while NLS continues to use an earlier value
(perhaps the one it saw when psql started??). As a result, seems unsetting
OUTPUT_CHARSET while psql is running can trigger this error.

We should address this case as well, or is it reasonable to ignore it as
an edge case?

Regards,

--
Fujii Masao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daria Lepikhova 2026-10-14 09:35:11 Re: Incremental backups report progress as if they were full backups
Previous Message Vaijayanti Bharadwaj 2026-10-14 09:27:45 Re: SSI: A patch for a Serializability violation