Postgres: Set Default Client Encoding

postgresqlutf-8

When querying from certain tables, I'll often receive the error:

character with byte sequence 0xef 0xbf 0xbd in encoding "UTF8" has no equivalent in encoding "WIN1252"

Varying bytes, but you get the idea. I can solve this by doing:

set client_encoding to 'UTF8';

But the (very) annoying thing is, I have to do this client_encoding set every. Single. Time. I open postgres. How do I set this to default?

Also, I am not asking how to change the encoding of a table's data, or of databases I create from now on–that's a different issue.

Best Answer

You can also set it as a default for any user or role (takes effect after a new connection is established):

ALTER ROLE <rolename> SET client_encoding = 'UTF8';