Postgres 数据库字符集更改 ERROR: new encoding (UTF8) is incompatible
来源:互联网 发布:女大十八变 知乎 编辑:程序博客网 时间:2024/06/02 22:54
今天去创建新环境装PG 并做2台PG库的主从同步。
装完库,发现库的默认字符集变成LATIN1. (因为自己偷懒,创建库的时候没有指定encoding)顿时感觉无语。因为最近各种库的莫名其妙乱码,中文乱码等N中乱码搞的难受。最后静下来 ,理了理思路。
1 . 没有去检查 /etc/profile 文件。应该在里面加入:
export LANG=en_US.UTF-8export LC_ALL=en_US.UTF-8export 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 template0update 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 template1update pg_database set datallowconn = FALSE where datname = 'template0';
至于pg库默认的template0 和template1 2个模板库到底是有什么用? 有待以后研究。
如果路过的各位有了解的,请多多赐教。
0 0
- Postgres 数据库字符集更改 ERROR: new encoding (UTF8) is incompatible
- Postgresql学习笔记 --- PG::Error: ERROR: new encoding (UTF8) is incompatible
- oracle更改数据库字符集编码UTF8
- postgres更改数据库用户密码
- ERROR:invalid byte sequence for encoding"UTF8"
- 更改mysql字符集utf8至utf8mb4
- Oracle10g更改数据库字符集
- 更改数据库字符集
- 更改ORACLE数据库字符集
- Oracle数据库更改字符集
- 20120412_更改Oracle字符集:把字符集ZHS16GBK换成UTF8
- 更改Oracle字符集:把字符集ZHS16GBK换成UTF8
- postgres更改数据库名的条件
- UTF8 encoding is longer than the max length 32766
- oracle数据库的字符集更改
- ERROR: invalid byte sequence for encoding "UTF8": 0x92
- Informix数据库对UTF8字符集的支持
- Informix数据库对UTF8字符集的支持
- 关于eclipse和maven配置问题
- nodejs学习笔记-nodejs的创建服务器(一)(http内置模块)
- CSS简单游戏代码(上机练习4)
- 广州智能服务机器人展览会 | 2016人工智能展
- flash builder 4.7安装以及破解
- Postgres 数据库字符集更改 ERROR: new encoding (UTF8) is incompatible
- iOS开发之NSDictionary与NSMutableDictionary
- 【机器学习】高斯过程python包安装过程
- 编程学习的网站收藏小集
- 金蝶KIS商贸版实现'条码标签打印'功能进行商品条码打印
- linux下socket编程实例
- android Camera 学习后续计划
- ART运行时Java堆创建过程分析
- android Canvas中的clipRect、drawBitmap