加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何更改Postgresql上的模板数据库集合编码

发布时间:2020-12-13 16:36:12 所属栏目:百科 来源:网络整理
导读:我想通过以下方式构建新的postgreSQL数据库: CREATE DATABASE newdbWITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'zh_CN.UTF-8' CONNECTION LIMIT = -1; 错误是: ERROR: new collation (zh_CN.UTF-8) is incompatible w
我想通过以下方式构建新的postgreSQL数据库:
CREATE DATABASE newdb
WITH OWNER = postgres
   ENCODING = 'UTF8'
   TABLESPACE = pg_default
   LC_COLLATE = 'zh_CN.UTF-8'
   CONNECTION LIMIT = -1;

错误是:

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.

如何更改模板数据库集合?使它成为(zh_CN.UTF-8)

从 PostgreSQL文档:

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创建具有不同编码和区域设置的新数据库:

CREATE DATABASE newdb
WITH OWNER = postgres
   ENCODING = 'UTF8'
   TABLESPACE = pg_default
   LC_COLLATE = 'zh_CN.UTF-8'
   CONNECTION LIMIT = -1
   TEMPLATE template0;

这将工作,但这意味着您对template1所做的任何更改将不会应用于新创建的数据库。

要更改template1的编码和排序规则,您必须先删除template1,然后从template0创建新的模板template1。如何删除模板数据库描述here.然后,您可以通过设置datistemplate = true(example)来创建具有所选编码/排序规则的新数据库template1并将其标记为模板:

update pg_database set datistemplate=true  where datname='template1';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读