如何在PostgreSQL中更改归类和ctype?

时间:2019-07-16 03:01:40

标签: postgresql

+-----------+----------+------------+----------------------------+----------------------------+-----------------------+
| Name      | Owner    | Encoding   | Collate                    | Ctype                      | Access privileges     |
|-----------+----------+------------+----------------------------+----------------------------+-----------------------|
| postgres  | postgres | UTF8       | English_United States.1252 | English_United States.1252 | <null>                |
| template0 | postgres | UTF8       | English_United States.1252 | English_United States.1252 | =c/postgres           |
|           |          |            |                            |                            | postgres=CTc/postgres |
| template1 | postgres | UTF8       | English_United States.1252 | English_United States.1252 | =c/postgres           |
|           |          |            |                            |                            | postgres=CTc/postgres |
+-----------+----------+------------+----------------------------+----------------------------+-----------------------+

CollateCtype的值在Linux上为C.UTF-8,但在Windows上为1252。

我可以将这些值更改为C.UTF-8吗?

1 个答案:

答案 0 :(得分:1)

您不能为已经创建的数据库更改这些值。此刻,当没有其他数据库时,最简单的解决方案是:a)停止数据库,b)删除数据目录,c)使用选项initdb--encoding手动--locale运行(在postgres用户下运行此命令)。 如果那里有一些数据,请先备份(使用pg_dump)。

您也可以在创建新数据库时更改这些参数(这是SQL命令):

CREATE DATABASE test ENCODING='UTF8' LOCALE='C' TEMPLATE='template0';

语言环境可以被COLLATECREATE TABLE命令中使用的子句SELECT覆盖。