在 PostgreSQL 中更改系统语言和错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/191428/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:09:54  来源:igfitidea点击:

Change language of system and error messages in PostgreSQL

postgresql

提问by Benno Richters

Is it possible to change the language of system messages from PostgreSQL?

是否可以从 PostgreSQL 更改系统消息的语言?

In MSSQL for instance this is possible with the SQL statement SET LANGUAGE.

例如,在 MSSQL 中,这可以通过 SQL 语句SET LANGUAGE 实现

回答by Milen A. Radev

SET lc_messages TO 'en_US.UTF-8';

More info on requirements and limitations here.

有关要求和限制的更多信息,请访问此处

回答by user1

Milen's answer didn't work for me.

米伦的回答对我不起作用。

I got it working by modifying a file postgresql.conf. If you're on Linux, write:

我通过修改文件让它工作postgresql.conf。如果您使用的是 Linux,请编写:

sudo find / -iname postgresql.conf

I had mine in /var/lib/pgsql/data. Then edit the file and search for a variable lc_messagesand change it to your preferred language, e.g. 'en_US.UTF-8'.

我有我的/var/lib/pgsql/data。然后编辑文件并搜索变量lc_messages并将其更改为您的首选语言,例如'en_US.UTF-8'.

If PostgreSQL stops working and you check in its log that you have an error that looks like this:

如果 PostgreSQL 停止工作并且您在其日志中检查您有如下错误:

invalid value for parameter "lc_messages": "en_US.UTF-8"

You have to edit /etc/locale.genand uncomment line with encoding from the error message (e.g. en_US.UTF-8). Then you have to run locale-gen(as root) to update the locales. Finally, to check if the locale is set you can run locale -a.

您必须/etc/locale.gen使用错误消息中的编码编辑和取消注释行(例如en_US.UTF-8)。然后您必须locale-gen(以 root 身份)运行以更新语言环境。最后,要检查是否设置了语言环境,您可以运行locale -a.

Or, if you want the language to be English, you can just set lc_messages = 'C'.

或者,如果您希望语言为英语,则只需设置lc_messages = 'C'.

回答by AndreKR

For me neither Milen A. Radev's nor user1's answer worked - editing PostgreSQL\11\data\postgresql.confhad absolutely no effect. Even after setting lc_messages = 'random value'PostgreSQL would still start.

对我来说,Milen A. Radev 和 user1 的回答PostgreSQL\11\data\postgresql.conf都没有奏效——编辑绝对没有效果。即使在设置后lc_messages = 'random value'PostgreSQL 仍然会启动。

What helped was to delete PostgreSQL\11\share\locale\*\LC_MESSAGES, after that I finally got English messages.

有帮助的是删除PostgreSQL\11\share\locale\*\LC_MESSAGES,之后我终于收到了英文信息。

回答by Birgit Vera Schmidt

In my case (on Windows Server 2019) I managed to change language by creating a system environment variable "LC_MESSAGES" with value "English":

就我而言(在 Windows Server 2019 上),我设法通过创建一个值为“English”的系统环境变量“LC_MESSAGES”来更改语言:

setx LC_MESSAGES English /m

(Solution taken from here)

(从这里采取的解决方案)