postgresql 编码 UTF8 与语言环境 en_US 不匹配;选择的 LC_CTYPE 设置需要编码 LATIN1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13115692/
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
encoding UTF8 does not match locale en_US; the chosen LC_CTYPE setting requires encoding LATIN1
提问by kamal
While trying to install opennms :
在尝试安装 opennms 时:
/usr/share/opennms/bin/install -l /usr/local/lib -dis
I get the error:
我收到错误:
ERROR: encoding UTF8 does not match locale en_US Detail: The chosen LC_CTYPE setting requires encoding LATIN1.
错误:编码 UTF8 与语言环境 en_US 不匹配 详细信息:所选的 LC_CTYPE 设置需要编码 LATIN1。
and I'm not sure how to proceed, as I've tried creating the DB several different ways (see below).
我不知道如何继续,因为我已经尝试通过几种不同的方式创建数据库(见下文)。
Full log:
完整日志:
==============================================================================
OpenNMS Installer
==============================================================================
Configures PostgreSQL tables, users, and other miscellaneous settings.
- searching for jicmp:
- trying to load /usr/local/lib/libjicmp.so: NO
- trying to load /usr/lib/jni/libjicmp.so: OK
- searching for jicmp6:
- trying to load /usr/local/lib/libjicmp6.so: NO
- trying to load /usr/lib/jni/libjicmp6.so: OK
- searching for jrrd:
- trying to load /usr/local/lib/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/lib/amd64/server/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/lib/amd64/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/../lib/amd64/libjrrd.so: NO
- trying to load /libjrrd.so: NO
- trying to load /usr/share/opennms/lib/libjrrd.so: NO
- trying to load /usr/share/opennms/lib/linux64/libjrrd.so: NO
- trying to load /usr/java/packages/lib/amd64/libjrrd.so: NO
- trying to load /usr/lib64/libjrrd.so: NO
- trying to load /lib64/libjrrd.so: NO
- trying to load /lib/libjrrd.so: NO
- trying to load /usr/lib/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/libjrrd.so: NO
- trying to load /usr/local/lib/libjrrd.so: NO
- trying to load /opt/NMSjicmp/lib/32/libjrrd.so: NO
- trying to load /opt/NMSjicmp/lib/64/libjrrd.so: NO
- trying to load /opt/NMSjicmp6/lib/32/libjrrd.so: NO
- trying to load /opt/NMSjicmp6/lib/64/libjrrd.so: NO
- Failed to load the optional jrrd library.
- This error is not fatal, since jrrd is only required for optional features.
- For more information, see http://www.opennms.org/index.php/jrrd
- using SQL directory... /usr/share/opennms/etc
- using create.sql... /usr/share/opennms/etc/create.sql
* using 'postgres' as the PostgreSQL user for OpenNMS
* using 'opennms' as the PostgreSQL database name for OpenNMS
Exception in thread "main" org.opennms.core.schema.MigrationException: an error occurred creating the OpenNMS database
at org.opennms.core.schema.Migrator.createDatabase(Migrator.java:428)
at org.opennms.core.schema.Migrator.prepareDatabase(Migrator.java:444)
at org.opennms.install.Installer.install(Installer.java:236)
at org.opennms.install.Installer.main(Installer.java:949)
Caused by: org.postgresql.util.PSQLException: ERROR: encoding UTF8 does not match locale en_US
Detail: The chosen LC_CTYPE setting requires encoding LATIN1.
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:366)
at org.opennms.core.schema.Migrator.createDatabase(Migrator.java:425)
... 3 more
List of databases:
数据库列表:
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
rhq | rhqadmin | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
I have used the following 3 initdb options but none of them work
我使用了以下 3 个 initdb 选项,但它们都不起作用
/usr/local/pgsql/bin/initdb -E UTF-8 --pgdata=/usr/local/pgsql/data
/usr/local/pgsql/bin/initdb -E LATIN1 --pgdata=/usr/local/pgsql/data
/usr/local/pgsql/bin/initdb -E en_US.UTF8 --pgdata=/usr/local/pgsql/data
Also, do i need to delete all data in /usr/local/pgsql/data
before i use initdb
?
另外,我需要在/usr/local/pgsql/data
使用之前删除所有数据initdb
吗?
appending locale command stdout:
附加语言环境命令标准输出:
$locale
$locale
LANG=en_US
LANGUAGE=en_US:
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=
采纳答案by mvp
Thanks for locale
output. OpenNMS seems to be using your en_US (non-UTF-8) locale in order to create postgres db, and this is wrong. This should work:
感谢您的locale
输出。OpenNMS 似乎正在使用您的 en_US(非 UTF-8)语言环境来创建 postgres 数据库,这是错误的。这应该有效:
export LANG=en_US.UTF-8
locale # confirm that it shows only en_US.UTF-8 for all settings
# finally, run your opennms installer
/usr/share/opennms/bin/install -l /usr/local/lib -dis
回答by Avia
I am answering this because nothing from StackOverFlow worked for me.
我正在回答这个问题,因为 StackOverFlow 中没有任何内容对我有用。
I combined two solutions from other sites that did the job (this answer works for Ubuntu server 12.04 and PGSQL 9.1):
我结合了来自其他网站的两个解决方案(这个答案适用于 Ubuntu 服务器 12.04 和 PGSQL 9.1):
Create a file:
创建一个文件:
nano /etc/profile.d/lang.sh
纳米 /etc/profile.d/lang.sh
Add the following
添加以下内容
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
Save it
保存
Restart shell or run all export commands manually in current shell instance
重新启动 shell 或在当前 shell 实例中手动运行所有导出命令
Reconfigure so the encoding can be UTF8 ([got it from here][1])
重新配置,使编码可以是 UTF8([从这里得到][1])
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
Use template1 for db creation.
使用 template1 进行数据库创建。
I hope this helps ;)
我希望这有帮助 ;)
回答by psychok7
this worked for me:
这对我有用:
CREATE DATABASE mydb WITH ENCODING='UTF8' LC_CTYPE='en_US.UTF-8' LC_COLLATE='en_US.UTF-8' OWNER=postgres TEMPLATE=template0 CONNECTION LIMIT=-1;
回答by Tomasz Iniewicz
This is happening because your system is setup to use Latin1 encoding instead of UTF-8. Your language is set correctly to en_US, but the encoding is not set to UTF-8. Try running this:$
发生这种情况是因为您的系统设置为使用 Latin1 编码而不是 UTF-8。您的语言已正确设置为 en_US,但编码未设置为 UTF-8。尝试运行这个:$
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
This will set tell all of your applications that are installed after the change (i think) to use the English language with unicode encoding. More information can be found here: https://www.linux.com/learn/docs/ldp/790-Unicode-HOWTO#s3
这将告诉您更改后安装的所有应用程序(我认为)使用带有 unicode 编码的英语语言。更多信息可以在这里找到:https: //www.linux.com/learn/docs/ldp/790-Unicode-HOWTO#s3
I had a similar issue so I:
我有一个类似的问题,所以我:
- aptitude purge postresql ...
- localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
- aptitude install postresql ....
- aptitude purge postresql ...
- localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
- aptitude 安装 postresql ....
and then postregsql knew to set itself to use the english language with unicode encoding.
然后 postregsql 知道将自己设置为使用具有 unicode 编码的英语语言。
Of course, you could do this on a per database basis as described here: http://www.postgresql.org/docs/9.1/static/multibyte.html
当然,您可以按照此处所述在每个数据库的基础上执行此操作:http: //www.postgresql.org/docs/9.1/static/multibyte.html
回答by jadeydi
I meet the similar error. old database LC_CTYPE is UTF-8, but new one is en_US.UTF-8, I solve the problem after reinit database.
我遇到了类似的错误。旧数据库LC_CTYPE是UTF-8,新数据库是en_US.UTF-8,reinit数据库后问题解决。
initdb --pgdata=/path/to/postgresql -E utf8
You should choice the right -E parameter
您应该选择正确的 -E 参数
回答by Taras Vaskiv
I have had the "same issue" while installing odoo. Turns out that before installing odoo you have to configure locale
我在安装 odoo 时遇到了“同样的问题”。原来,在安装 odoo 之前,您必须配置语言环境
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
And then configuler locale with UTF-8 BUT you have to configure locale before posgres installation.
然后使用 UTF-8 配置语言环境,但您必须在 posgres 安装之前配置语言环境。
回答by Igor Palácio
Change the locales and languages of SO for compatibilty with BD.
更改 SO 的区域设置和语言以与 BD 兼容。
dpkg-reconfigure locales
dpkg-重新配置语言环境
enjoy!
请享用!