微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想通过以下方式构建新的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';

原文地址:https://www.jb51.cc/postgresql/192917.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐