When I connect to a Postgresql DB using psql
, I often get these messages:
=> SELECT * FROM question_view ;
ERROR: character with byte sequence 0xd7 0x9e in encoding "UTF8" has no equivalent in encoding "LATIN1"
Following this SO answer, I understand that I should change the client encoding accordingly:
SET client_encoding = 'UTF8';
Changing the client_encoding
every time I connect to the DB is cumbersome. Is there a way to permanently configure this setting, either in the .pgpass
file or anywhere else?
2 Answers 2
Is there a way to permanently configure this setting, either in the .pgpass file or anywhere else
Yes there is: it's ~/.psqlrc
(or %APPDATA%\postgresql\psqlrc.conf
in Windows)
See the manual for details: http://www.postgresql.org/docs/current/static/app-psql.html#AEN88713
-
3Adding
SET client_encoding = 'UTF8';
to~/.psqlrc
did the trick. Thanks!Adam Matan– Adam Matan2014年07月15日 21:21:55 +00:00Commented Jul 15, 2014 at 21:21 -
This doesn't seem to work when (re)connecting from within a
psql
session, for example after restarting the server.Adam Mackler– Adam Mackler2014年08月20日 18:07:09 +00:00Commented Aug 20, 2014 at 18:07 -
1I had to create this file in Windows and then set a user environment var called PSQLRC pointing to that directory. No more complaints, yayAlkanshel– Alkanshel2016年01月06日 20:13:59 +00:00Commented Jan 6, 2016 at 20:13
I was facing the same error but changing from ANSI(X64) to Unicode(x64) in my ODBC conn fixed my issue.
Explore related questions
See similar questions with these tags.