Oracle迁移Postgresql 遇到的一些问题记录

来源:互联网 发布:linux退出for循环 编辑:程序博客网 时间:2024/06/05 15:54

项目环境:Oracle 数据库 及 Postgresql数据库 Play Framework框架 Linux服务器

迁移数据库只是为了了解Postgresql数据库,初步在网上搜索迁移的方法,有一个现成的迁移工具,不过对英语不过关,需要下载和配置一些东西没有成功。还是项目经理说了另一个方法,成功了,就是使用PowerDesiger软件。首先得到Oracle 建表语句

1.得到Oracle建表语句,可以从数据库导出,或是项目自带的建表语句,导入到PowerDesiger软件中:File>Reverse Enineer>Database…


选择对应的数据库确定后选择加载文件,软件会生成数据库建模图。然后选择Database>Change Current DBMS…改变数据库类型,这样这些数据库的建表语句就转换对应的数据库语句了。

建立对应Postgresql库及用户名,导入建表语句。

1.首先是项目启动报错: ERROR ~ Cannot connected to the database : Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.这个额错误网上有很多解解方法都是统一的就是修改两个配置文件,说是现在了ip访问或端口不对。自己也改了配置可是还是一直报这个错误,非常郁闷,找了领导总于解决……哎。原来是服务器的iptables防火墙服务启动了,以前这个服务一直都是关闭的,不知道谁给启动了。

2.项目中的查询语句中用到了rownum,postgresql里没有:"select 'allJobCode2Group' as T,job_code as K,(select tug.groups_id from t_user_group tug,t_group tg where tug.groups_id=tg.id and tg.if_use=1 and tug.users_id=u.id and rownum=1) as V from t_user u"其实我没看懂这里的rownum的作用,在命令里查询把rownum去掉后的查询结果跟之前的查询结果一样,就直接去掉了……。

3.wm_concat Postgresql里没有得用(array_to_string,array_agg)这样写:mysql(ERROR: function group_concat(bigint) does not exist)

 dic.groupUser=select '${emCode}_groupUser' as T,groups_id as K,array_to_string(array_agg(users_id),',') as V from cc_user_group group by groups_id;

4.Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: boolean = integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 68

之前是把boolean 类型都换成了项目中int类型,数据库中numeric类型。

然后找到问题所在是项目中有一部分原sql语句是这样写的:

 - name: userList
   type: sql
   data: "select 'userList' as T,id as K,real_name as V from t_user where if_use=1;"

这里的if_use=1引起的错误,需要把1加上单引号。

5.ERROR: relation "user_sequences" does not exist;

建表的时候注意需要赋予相应的用户权限。这是网上找的可是我的是多用户多个库……,用户都是管理员啊。

[sql] view plaincopyprint?
  1. ALTER TABLE "userInfo"  
  2.   OWNER TO sa;  
  3. GRANT ALL ON TABLE "userInfo" TO sa;  
  4. GRANT ALL ON TABLE "userInfo" TO public;  

0 0
原创粉丝点击