Linux 上的 PostgreSQL 10 - LC_COLLATE 语言环境 en_US.utf-8 无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49783108/
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 10 on Linux - LC_COLLATE locale en_US.utf-8 not valid
提问by Nathan Smith
ERROR: invalid locale name: "en_US.utf-8"
错误:无效的语言环境名称:“en_US.utf-8”
Running Ubuntu server 18.04 Beta 2 with PostgreSQL 10.
使用 PostgreSQL 10 运行 Ubuntu 服务器 18.04 Beta 2。
In running a database creation script that worked on 9.5, I am now seeing an issue with 'en_US.UTF-8' as a locale:
在运行适用于 9.5 的数据库创建脚本时,我现在看到“en_US.UTF-8”作为语言环境的问题:
CREATE DATABASE db WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
I know this may be redundant as I understand the default to be 'en_US.etf-8'. Removing the LC_COLLATE and LC_CTYPE parameters let me run my script.
我知道这可能是多余的,因为我理解默认值为“en_US.etf-8”。删除 LC_COLLATE 和 LC_CTYPE 参数让我可以运行我的脚本。
So did the locale definitions change somehow for V 10? Or is there something else now happening? I couldn't find anything on this in the Postgres 10 manual.
那么 V 10 的语言环境定义是否发生了某种变化?或者现在还有其他事情发生吗?我在 Postgres 10 手册中找不到任何关于此的内容。
回答by Vao Tsun
check for available locales with locale -a
if not found, try manually adding it with:
检查可用的语言环境,locale -a
如果未找到,请尝试手动添加:
locale-gen en_US.UTF-8
after this
在这之后
CREATE DATABASE db WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
should work
应该管用
回答by wil93
I had the same error, I generated the new locale:
我有同样的错误,我生成了新的语言环境:
locale-gen en_US.UTF-8
I verified with locale -a
that it was in fact present, then I logged out just to make sure, but I was still getting the same error on the database creation.
我确认locale -a
它确实存在,然后我注销只是为了确保,但我仍然在创建数据库时遇到相同的错误。
Finally, I solved the error by simply restarting the postgresql server with:
最后,我通过简单地重新启动 postgresql 服务器解决了这个错误:
sudo systemctl restart postgresql
After that, the database creation command was working!
之后,数据库创建命令开始工作了!
回答by Manuel Lazo
It's been performed on kubuntu and works perfectly, with some additional steps previously mentioned above, the right steps should be:
它已在 kubuntu 上执行并完美运行,加上前面提到的一些额外步骤,正确的步骤应该是:
Validate the existence; if it doesn't exist, proceed to create it (will require sudo privileges)
locale -a |grep -i 'es_ES.utf-8' sudo locale-gen es_PE.UTF-8
Validate if the locale was created.
locale -a|grep -i es es_ES.utf8 es_PE.utf8
After the creation of the locale proceed to restart the postgres service, otherwise u will be getting the following error :
ERROR: invalid locale name: "es_ES.UTF-8"
Restart the postgres service
systemctl restart postgresql
Finally, database was created.
postgres=# create database db_izipay_prod with template=template0 encoding='utf8' lc_collate='es_ES.UTF-8' lc_ctype='es_ES.UTF-8' owner=postgres; CREATE DATABASE
验证存在;如果它不存在,继续创建它(需要 sudo 权限)
locale -a |grep -i 'es_ES.utf-8' sudo locale-gen es_PE.UTF-8
验证是否创建了语言环境。
locale -a|grep -i es es_ES.utf8 es_PE.utf8
创建语言环境后,继续重新启动 postgres 服务,否则您将收到以下错误:
ERROR: invalid locale name: "es_ES.UTF-8"
重启 postgres 服务
systemctl restart postgresql
最后,创建了数据库。
postgres=# create database db_izipay_prod with template=template0 encoding='utf8' lc_collate='es_ES.UTF-8' lc_ctype='es_ES.UTF-8' owner=postgres; CREATE DATABASE