星期四, 十月 04, 2012

Postgresql中创建Unicode(UTF8)编码的数据库


为了数据显示一致性,现在网站存储中文数据时一般都会用utf8编码,但是在postgresql中用以下命令创建数据库时,会出错
create database my_db encoding='utf8';
提示错误:ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
这是因为Postgresql创建数据库时实际上是从已有模板中复制,系统默认使用template1,但是这个模板不支持utf8编码,所以命令稍做修改即可
create database my_db template template0 encoding='utf8';
关于postgresql中模板以及创建数据库更详细的信息可以参考:http://www.pgsqldb.org/pgsqldoc-8.1c/manage-ag-templatedbs.html

没有评论: