如何更改模板数据库集合的编码 [英] How to change the template database collection coding
问题描述
我想通过以下方式构建新的postgreSQL数据库:
I want build new postgreSQL database by:
CREATE DATABASE newdb
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1;
,错误是:
错误:新排序规则(zh_CN.UTF-8)与模板数据库的排序规则(en_US.UTF8)不兼容。
提示:使用与模板数据库相同的排序规则,或使用template0作为模板。
ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF8)
HINT: Use the same collation as in the template database, or use template0 as template.
如何更改模板数据库集合?
How to change the template database collection?
推荐答案
来自 PostgreSQL 文档:
复制template0而不是template1的另一个常见原因是
,可以指定新的编码和区域设置复制
template0时,而template1的副本必须使用
相同的设置。这是因为template1可能包含特定于编码的数据或
特定于语言环境的数据,而众所周知template0则不包含。
Another common reason for copying template0 instead of template1 is that new encoding and locale settings can be specified when copying template0, whereas a copy of template1 must use the same settings it does. This is because template1 might contain encoding-specific or locale-specific data, while template0 is known not to.
您只能使用 template0
创建具有不同编码和区域设置的新数据库:
You can use only template0
to create new database with different encoding and locale:
CREATE DATABASE newdb
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1
TEMPLATE template0;
这将起作用,但这意味着您对 template1所做的任何更改/ code>不会应用于新创建的数据库。
This will work, however it means that any changes you made to template1
won't be applied to newly created database.
更改 template1
您必须首先删除 template1
,然后从 template0 $创建新模板
template1
c $ c>。 此处中介绍了如何删除模板数据库。然后,您可以使用选择的编码/排序规则创建新的数据库 template1
,并通过设置 datistemplate = true
将其标记为模板。 示例):
To change encoding and collation of template1
you have to first delete template1
and then create new template template1
from template0
. How to drop template database is described here. Then you can create new database template1
with chosen encoding/collation and mark it as a template by setting datistemplate=true
(example):
update pg_database set datistemplate=true where datname='template1';
这篇关于如何更改模板数据库集合的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!