How to set client_encoding?

Grant McLean <[email protected]> Tue, 07 Jan 2020 10:55:30 +1300
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <[email protected]>
Hi

I've just noticed that the DBD::Pg documentation recommends removing any
mention of the 'pg_enable_utf8' connection attribute and instead relying
on the default behaviour which is based on the 'client_encoding'.
What's not clear to me is how I would ensure that 'client_encoding' gets
set correctly.

It looks like libpq will set the client_encoding based on the value of
LC_CTYPE or PGCLIENTENCODING. Is there some way to specify the client
encoding in the DBI->connect() call or should I just set the
PGCLIENTENCODING environment variable before connecting?

I want to use UTF8 as the client encoding, but for "reasons" (possibly
relating to legacy expectations around collation order) my clients will
have LC_CTYPE set to "POSIX".

Ultimately, I think a POD patch to DBD::Pg is probably required since
the docs currently say that client_encoding is important but don't say
how to set it.

Thanks
Grant