database postgresql initdb 出了什么问题?为什么没有强制执行`UTF-8` 编码?

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

What is going wrong with postgresql initdb? Why is the `UTF-8` encoding not getting enforced?

databasepostgresqlpostgresql-9.1

提问by ThinkingMonkey

I am using PostgreSQL 9.1. Trying to enforce UTF8 encoding as default.

我正在使用 PostgreSQL 9.1。尝试将 UTF8 编码强制为默认值。

This is what I am doing.

这就是我正在做的。

service postgresql initdb -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype=locale='en_US.UTF-8';

Although the initilization process goes on without any problem,

虽然初始化过程没有任何问题,

a \lat the psqlprompt gives there details.

提示\l处的apsql提供了详细信息。

                         List of databases
   Name    |  Owner   |Encoding  | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
  postgres | postgres | LATIN1 | en_US | en_US| 

Why is the UTF-8encoding not getting enforced?

为什么UTF-8编码没有得到强制执行?

回答by Eelke

Looks like you are calling initdb through a runlevel script of the OS. This script might not pass on the parameters. You better try executing initdb directly, you will need to perform the following steps starting as root and assuming the OS user account for the database is postgres.

看起来您正在通过操作系统的运行级别脚本调用 initdb。此脚本可能不会传递参数。您最好尝试直接执行 initdb,您需要以 root 身份开始执行以下步骤,并假设数据库的操作系统用户帐户是 postgres。

mkdir <your data dir>
chown postgres <your data dir>
su postgres
initdb --pgdata=<your data dir> -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8'

回答by jaydip

Debian PostgreSQL installation automatically calls the initdb i.e. it initializes the cluster with default encoding and locale. Encoding can be changed later but the locale cannot. To change the locale (an possibly other options in initdb), delete the existing default cluster and create a new one:

Debian PostgreSQL 安装会自动调用 initdb,即它使用默认编码和语言环境初始化集群。编码可以稍后更改,但语言环境不能。要更改区域设置(initdb 中可能还有其他选项),请删除现有的默认集群并创建一个新集群:

Take root privileges.
Run the following command:



 pg_dropcluster --stop <version> main

For example:

pg_dropcluster --stop 8.3 main

Run the initdb with your options. For example:

pg_createcluster --locale de_DE.UTF-8 --start 8.3 main

Warning!

警告!

The previous operation obviously deletes everything you had in cluster databases. Perform this operation right after you have installed the base package. Check the PostgreSQL manual if you need to change locale for an existing database (it is not a trivial operation).

前面的操作显然会删除您在集群数据库中的所有内容。安装基础包后立即执行此操作。如果您需要更改现有数据库的语言环境,请查看 PostgreSQL 手册(这不是一项简单的操作)。