首页 > 解决方案 > PostgreSQL 安装问题 Character Type

问题描述

我使用默认数据库 postgres 安装了 PostgreSQL 9.2。它将排序规则和字符类型显示为 en_GB.UTF-8。

en_GB 和 en_US 之间有什么区别吗?我可以在不卸载的情况下更改为 en_US。

标签: character-encodingpsqlpostgresql-9.3

解决方案


第一个选项是在创建新数据库时,您可以提供 Collat​​ion 和 Ctype 之类的

postgres=# CREATE DATABASE test  WITH LC_COLLATE='en_US'  Encoding='LATIN1' lc_ctype='en_US' TEMPLATE=template0;;
CREATE DATABASE


postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 test      | postgres | LATIN1   | en_US       | en_US       | 
(4 rows)

第二种选择是执行新的 initdb 并提供 -E 编码和 --locale=locale。设置数据库集群的默认语言环境。如果未指定此选项,则从 initdb 运行的环境继承语言环境

在postgres initdb中使用 --locale 查看有关 initdb 的更多详细信息

披露:我为EnterpriseDB (EDB)工作


推荐阅读