Postgres 数据库字符集更改 ERROR: new encoding (UTF8) is incompatible
2016-10-14 17:07
423 查看
今天去创建新环境装PG 并做2台PG库的主从同步。
装完库,发现库的默认字符集变成LATIN1. (因为自己偷懒,创建库的时候没有指定encoding)顿时感觉无语。因为最近各种库的莫名其妙乱码,中文乱码等N中乱码搞的难受。最后静下来 ,理了理思路。
1 . 没有去检查 /etc/profile 文件。应该在里面加入:
整体的环境变量如果设置好了也不会出现后面的事。postgres用户也不会变成别的字符集。
2.. postgres 到现在还没有什么语句能像ORACLE一样能直接转换字符集的命令。
所以我们能想到的仅仅是把数据导出 ,新建库,然后再导入。这里导入导出就不多说了。
附一个建库的语句:
3 .好了 事情又来了 ,报错
ERROR: new encoding (utf8) is incompatible with the encoding of the template database.
原来我这个不仅创建的数据库字符集是LATIN1 ,连postgres和template 0 和template1 都是LATIN1.
下面是解决代码:
至于pg库默认的template0 和template1 2个模板库到底是有什么用? 有待以后研究。
如果路过的各位有了解的,请多多赐教。
装完库,发现库的默认字符集变成LATIN1. (因为自己偷懒,创建库的时候没有指定encoding)顿时感觉无语。因为最近各种库的莫名其妙乱码,中文乱码等N中乱码搞的难受。最后静下来 ,理了理思路。
1 . 没有去检查 /etc/profile 文件。应该在里面加入:
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 export LC_CTYPE=en_US.UTF-8
整体的环境变量如果设置好了也不会出现后面的事。postgres用户也不会变成别的字符集。
2.. postgres 到现在还没有什么语句能像ORACLE一样能直接转换字符集的命令。
所以我们能想到的仅仅是把数据导出 ,新建库,然后再导入。这里导入导出就不多说了。
附一个建库的语句:
create database test with encoding = 'UTF8' LC_CTYPE = 'en_US.UTF-8' LC_COLLATE = 'en_US.UTF-8' template = template1;
3 .好了 事情又来了 ,报错
ERROR: new encoding (utf8) is incompatible with the encoding of the template database.
原来我这个不仅创建的数据库字符集是LATIN1 ,连postgres和template 0 和template1 都是LATIN1.
下面是解决代码:
update pg_database set datallowconn = TRUE where datname = 'template0'; \c template0 update pg_database set datistemplate = FALSE where datname = 'template1'; drop database template1; create database template1 with encoding = 'UTF8' LC_CTYPE = 'en_US.UTF-8' LC_COLLATE = 'en_US.UTF-8' template = template0; update pg_database set datallowconn = TRUE where datname = 'template1'; \c template1 update pg_database set datallowconn = FALSE where datname = 'template0';
至于pg库默认的template0 和template1 2个模板库到底是有什么用? 有待以后研究。
如果路过的各位有了解的,请多多赐教。
相关文章推荐
- Postgresql学习笔记 --- PG::Error: ERROR: new encoding (UTF8) is incompatible
- 我oracle数据库安装完了,字符集是ZHS16GBK,但是我需要一个数据库字符集是UTF8的,怎么办?。新建一个数据库实例,选择字符集为utf8即可
- Oracle10g更改数据库字符集
- 更改oracle字符集 error: ora-12712 解决方法
- HTML页面设置的字符集会影响发送到MySQL的字符集,所以当数据库字符集为utf8时,HTML页面也要设置字符集为utf8,中文乱码的一种解决办法
- MySQL字符集 GBK、GB2312、UTF8区别 解决 MYSQL中文乱码问题以及error 1406:data too long for column 'name' at row 1
- oracle9i数据库字符集为ASCII码,数据导入oracle11g字符集为utf8的数据库中。
- ORACLE11g数据库字符集从ZHS16GBK转为UTF8遗留问题的解决
- 在oracle中,怎么新建一个字符集是utf8的数据库(即数据库实例)
- 20120412_更改Oracle字符集:把字符集ZHS16GBK换成UTF8
- 更改mysql字符集utf8至utf8mb4
- oracle更改数据库字符集编码!
- 重置mysql Root用户密码及修改默认字符集一般就算设置了表的默认字符集为utf8并且通过UTF-8编码发送查询,你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。 解决
- postgres数据库存储目录 更改
- mysql创建数据库,设置charset为utf8,并使用utf8_general_ci字符集校验结果
- MySQL之对数据库库表的字符集的更改
- mysql 建立utf8字符集数据库
- 手工更改数据库字符集
- Fedora19更改postgres数据目录,并创建用户初始化数据库
- Informix数据库对UTF8字符集的支持