SQL PostgreSQL:在 Windows 上使用 psql 命令行实用程序时的编码问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20952893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL: encoding problems on Windows when using psql command line utility
提问by Frank N Stein
I'm working in a centralized monitoring system on Windows 2008 R2, I have installed a PostgreSQL 9.3 to use psqlfrom the command line.
我在 Windows 2008 R2 上的集中监控系统中工作,我安装了 PostgreSQL 9.3 以从命令行使用psql。
When I try to access to some remote Postgres (an 8.4 in my principal case) I have an error with the encoding:
当我尝试访问某些远程 Postgres(在我的主要情况下为 8.4)时,我遇到了编码错误:
command:
命令:
psql.exe -h 192.168.114.12 -p 5432 -d db_seros_transaccion -U postgres -f script.sql
error:
错误:
psql: FATAL: la conversión entre WIN1252 y LATIN1 no está soportada
I try adding the sentence
我尝试添加句子
SET client_encoding = 'UTF8';
in my script but the problem persist (and with other encodings too, like LATIN1 & WIN1252).
在我的脚本中,但问题仍然存在(以及其他编码,如 LATIN1 和 WIN1252)。
After googling it I found people that update some rows in the server to make the connection, and this is a problem to me.
谷歌搜索后,我发现有人更新服务器中的某些行以建立连接,这对我来说是个问题。
Can anyone help me to make a connection using psqlwithout an update? Is it possible?
任何人都可以帮助我在没有更新的情况下使用psql建立连接吗?是否可以?
回答by Frank N Stein
Thanks a lot Craig Ringer, works, finally works! You are my new idool now!
非常感谢Craig Ringer,有效,终于有效!你现在是我的新偶像了!
The steps are:
步骤是:
- open the cmd
- SET PGCLIENTENCODING=utf-8
- chcp 65001
- psql -h your.ip.addr.ess -U postgres
- 打开cmd
- 设置 PGCLIENTENCODING=utf-8
- CHCP 65001
- psql -h your.ip.addr.ess -U postgres