强制Postgres使用UTF8编码安装,而不是LATIN1? [英] Force Postgres to install with UTF8 encoding, not LATIN1?
问题描述
我试图在Vagrant框上设置CartoDB,按照这里的说明。然而,它仍然失败,因为它抱怨Postgres已经安装了Latin-1编码。
I'm trying to set up CartoDB on a Vagrant box, following the instructions here. However, it keeps failing because it complains that Postgres has been installed with Latin-1 encoding.
我不明白为什么Postgres正在做这件事,因为我明确强制所有本地设置为UTF8。这是我一直在做的:
I can't work out why Postgres is doing this, because I'm explicitly forcing all the local settings to UTF8. Here's what I've been doing:
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
locale
sudo apt-get update
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:cartodb/gis
sudo add-apt-repository -y ppa:mapnik/v2.1.0
sudo add-apt-repository -y ppa:cartodb/nodejs
sudo add-apt-repository -y ppa:cartodb/redis
sudo add-apt-repository -y ppa:cartodb/postgresql
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y make unp zip libgeos-c1 libgeos-dev gdal-bin libgdal1-dev libjson0
sudo apt-get install python-simplejson libjson0-dev proj-bin proj-data libproj-dev postgresql-9.1
早期 locale
的输出,显示UTF8已成功设置:
Here is the output of the early locale
, showing that UTF8 has been set successfully:
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
运行所有上述命令后,我检查Postgres的状态,似乎Postgres用Latin-1编码安装:
After running all the above commands, when I check the status of Postgres, it seems Postgres nonetheless installed itself with Latin-1 encoding:
sudo -u postgres psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | 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
为什么会发生这种情况?如何强制Postgres安装自己的UTF8编码?
Why is this happening? How can I force Postgres to install itself with UTF8 encoding?
推荐答案
这可能不是你要找的答案,但在这里是可以用于将PostgreSQL切换到其他语言环境的命令(备份,重新创建集群和还原):
This might not be the answer you are looking for, but here are commands which you can use to switch PostgreSQL to a different locale (backup, re-create cluster and restore):
sudo -u postgres pg_dumpall > /tmp/postgres.sql
sudo pg_dropcluster --stop 9.1 main
sudo pg_createcluster --locale en_US.UTF-8 --start 9.1 main
sudo -u postgres psql -f /tmp/postgres.sql
如果你想知道为什么安装使用拉丁语,那么你可能需要挖掘安装脚本。但是如果 en_US.UTF-8
不是您的默认系统区域设置,那可能是问题。安装脚本可以加载 / etc / default / locale
。
If you want to know why the installation uses Latin, then you might need to dig into installation scripts. But if en_US.UTF-8
is not your default system locale, that might be the problem. Installation script can be loading /etc/default/locale
.
这篇关于强制Postgres使用UTF8编码安装,而不是LATIN1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!