ora2pg 字符集 转换问题总结

近期做了oracle 转pg 的数据库转换测试:

使用了开源工具 ora2pg    http://ora2pg.darold.net/  

前期的测试 设定的条件太多了,都忘记情景了,

就直接写 问题和解决方案了

pg  initdb 的时候,指定为utf8编码,  导出的文本为gbk 编码,生成文本数据导入pg 的时候,一些非正常的字符,例如全角字符的一半



会导致无人进入pg 数据库。 


最终解决方案: 
ora2pg.conf  
 文件中 : 

设置   NLS_LANG        AMERICAN_AMERICA.UTF8 

导入pg 的时候 设定字符集: 

psql > \encoding  UTF8 


这样导入的数据是utf8编码的,在psql 里是无法查看的。 

需要设定  

psql >  \encoding  GB18030  

如果设置 GBK 字符集 会报错类似于:


sns_pclady=> \encoding GBK;                                                    
sns_pclady=> select * from sns_album where id=97979 ;
ERROR:  character 0xeea097 of encoding "UTF8" has no equivalent in "GBK"
STATEMENT:  select * from sns_album where id=97979 ;
ERROR:  character 0xeea097 of encoding "UTF8" has no equivalent in "GBK"
sns_pclady=> \encoding GB18030
sns_pclady=> select * from sns_album where id=97979 ;
  id   | account_id |                                 album_name                                 | album_cover | pic_count | hidden | is_system | censor | censor_status | censor_date |     create_time     |     last_update     | pending_time | version | commend | commend_time | has_audit | last_repaste | isstandby | readonly
-------+------------+----------------------------------------------------------------------------+-------------+-----------+--------+-----------+--------+---------------+-------------+---------------------+---------------------+--------------+---------+---------+--------------+-----------+--------------+-----------+----------
 97979 |   13071971 | ÈÈÏߵ绰¡¾£´£°£°þR£¶£¶£¹¡¨þR£·£¶£·£¸¡¿Ïû·ÑÕß0571-888198É̼Ò058857858 |             |         0 |      3 |         0 |        |             1 |             | 2010-06-03 21:56:08 | 2010-06-03 21:56:08 |              |       1 |         |              |         0 |              |           |        0
(1 row)

请使用浏览器的分享功能分享到微信等