PostgreSQL:警告:控制台代码页 (437) 与 Windows 代码页 (1252) 不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20794035/
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: Warning: Console code page (437) differs from Windows code page (1252)
提问by Yousuf Memon
Using PostgreSQLwhen I connectto a db using \c testdb
inside PostgreSQL Database SQL Prompt. I successfully connect to the db but getting the following warning:
使用PostgreSQL的,当我连接到使用DB \c testdb
PostgreSQL数据库SQL提示里面。我成功连接到数据库,但收到以下警告:
postgres-# \c testdb
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
You are now connected to database "testdb" as user "postgres".
testdb-#
What does this warning mean? How to resolve it?
这个警告是什么意思?如何解决?
回答by dvdgsng
From the psql documentation:
从psql 文档:
psql is built as a "console application". Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8-bit characters within psql. If psql detects a problematic console code page, it will warn you at startup.
To change the console code page, two things are necessary: Set the code page by entering cmd.exe /c chcp 1252. (1252 is a code page that is appropriate for German; replace it with your value.) If you are using Cygwin, you can put this command in /etc/profile.
psql 是作为“控制台应用程序”构建的。由于 Windows 控制台窗口使用与系统其余部分不同的编码,因此在 psql 中使用 8 位字符时必须特别小心。如果 psql 检测到有问题的控制台代码页,它会在启动时警告您。
要更改控制台代码页,需要做两件事: 通过输入 cmd.exe /c chcp 1252 设置代码页。(1252 是适合德语的代码页;用您的值替换它。)如果您使用的是 Cygwin , 你可以把这个命令放在 /etc/profile.d 中。
So to remove that warning you need to execute chcp 1252
before you enterpsql
. Using chcp
without parameters gives you the current codepage.
因此,要删除该警告,您需要chcp 1252
在输入之前执行psql
。chcp
不带参数使用可为您提供当前代码页。
回答by numbers longer
To make it even more obvious, the file to which @user3423801 is adding the line
更明显的是,@user3423801 添加行的文件
cmd.exe /c chcp 1252
is in the scripts
directory where you installed Postgre.
位于scripts
您安装 Postgre的目录中。
For example, in my case it is
例如,就我而言,它是
C:\Program Files\PostgreSQL.3\scripts\runpsql.bat
回答by user3344137
The default codepage for CMD.exe is different than the default for postgres... To change for CMD.exe using the REGISTRY try this:
CMD.exe 的默认代码页与 postgres 的默认代码页不同...要使用 REGISTRY 更改 CMD.exe,请尝试以下操作:
- Start -> Run -> regedit
- Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
- Add new string value named "Autorun" with value "chcp 1252"
- 开始 -> 运行 -> regedit
- 转到 [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
- 添加名为“Autorun”的新字符串值,值为“chcp 1252”
Then reopen CMD.exe
然后重新打开CMD.exe
回答by user3344137
Open cmd.exe and run regedit
.
打开 cmd.exe 并运行regedit
.
Go to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
去 Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
New a string value named: Autorun
and change the value to be chcp 1252
新建一个名为:的字符串值Autorun
,并将值更改为chcp 1252
Done.
完毕。
Reference: https://stackoverflow.com/a/30100565/8396969
回答by iusting
Or you can simply type cmd.exe /c chcp 1252
in the Command Prompt window.
或者您可以简单地cmd.exe /c chcp 1252
在命令提示符窗口中键入。
回答by user3423801
The answer of dvdgsng is correct but with code example is more obviously.
dvdgsng 的答案是正确的,但代码示例更明显。
@echo off
REM Copyright (c) 2012-2014, EnterpriseDB Corporation. All rights reserved
REM PostgreSQL server psql runner script for Windows
cmd.exe /c chcp 1252
SET server=localhost
SET /P server="Server [%server%]: "
回答by Damien Sawyer
I couldn't figure out how to set it for Cygwin globally. This seemed to work though in my bash script
我不知道如何在全球范围内为 Cygwin 设置它。这似乎在我的 bash 脚本中有效
#!/bin/bash
cmd.exe /c chcp 1252 && psql -h myserver.postgres.database.azure.com -U myuser@prod-au -d mydatabase
回答by Rich Lysakowski PhD
The answers above are okay, but don't mention anywhere that Windows 1252 encoding is good for English language versions of Windows AND the other Western European Languages. This completes the answer for those people who may get confused about the aforementioned application to German language encoding. Yes it works for English without umlauts and other special characters needed for German, Spanish, French, Italian, Romanian, Hungarian, etc.
上面的答案是可以的,但不要在任何地方提及 Windows 1252 编码适用于英语版本的 Windows 和其他西欧语言。这完成了那些可能对上述德语编码应用感到困惑的人的答案。是的,它适用于没有变音符号和德语、西班牙语、法语、意大利语、罗马尼亚语、匈牙利语等所需的其他特殊字符的英语。
https://en.m.wikipedia.org/wiki/Windows-1252
https://en.m.wikipedia.org/wiki/Windows-1252
What is Windows 1252 encoding?
什么是 Windows 1252 编码?
Windows-1252 or CP-1252 (code page 1252) is a single-byte character encoding of the Latin alphabet, used by default in the legacy components of Microsoft Windows for English and some other Western languages (other languages use different default encodings).
Windows-1252 或 CP-1252(代码页 1252)是拉丁字母表的单字节字符编码,默认情况下用于英语和其他一些西方语言的 Microsoft Windows 的旧组件(其他语言使用不同的默认编码)。
回答by Rich Lysakowski PhD
Please don't assume that Unix fixes work for Windows Users. For Windows 10, and PostgreSQL 12, combining the answers by "user3423801" and "numbers longer" worked for me. (The Windows Registry hack would not work. I did not try rebooting yet.) It is better to fix it in the PSQL startup script anyway.
请不要假设 Unix 修复程序适用于 Windows 用户。对于 Windows 10 和 PostgreSQL 12,结合“user3423801”和“数字更长”的答案对我有用。(Windows Registry hack 不起作用。我还没有尝试重新启动。)无论如何最好在PSQL 启动脚本中修复它。
The file location C:\Program Files\PostgreSQL\12\scripts
contains the file runpsql.bat
, into which you must insert the cmd.exe /c chcp 1252 command
in the right location. So the top of your edited file should look like the 5 or 6 lines below.
文件位置C:\Program Files\PostgreSQL\12\scripts
包含文件runpsql.bat
,您必须cmd.exe /c chcp 1252 command
在正确的位置插入文件。所以你编辑过的文件的顶部应该看起来像下面的 5 或 6 行。
@echo off
REM Copyright (c) 2012-2014, EnterpriseDB Corporation. All rights reserved
REM PostgreSQL server psql runner script for Windows
cmd.exe /c chcp 1252
SET server=localhost
SET /P server="Server [%server%]: "
回答by You sir
Basically, set your console application encoding from 8-bit to utf-8.
基本上,将您的控制台应用程序编码从 8 位设置为 utf-8。
For git bashusers
run the command chcp.com 1252
before running postgres
对于git bash用户,chcp.com 1252
在运行 postgres 之前运行命令
chcp is a windows console command, so to execute it on git bash you might need to add .com
chcp 是 Windows 控制台命令,因此要在 git bash 上执行它,您可能需要添加 .com
git bash can't extend chcp to a full executable on its own, so you need to type the full command.
git bash 自身无法将 chcp 扩展为完整的可执行文件,因此您需要键入完整的命令。