您的位置:首页 > 数据库

两个postgresSQL数据库对象比对

2015-12-08 22:50 411 查看
1.环境

数据库dev:开发数据库

数据库prod:生成数据库

2.背景

最近在dev上做了大量模型改造,需要把修改的地方同步到生产数据库prod中,但是每一步改动并没有详细的记录,且新增加的对象不能同步上去。

3.实现

pg_dump -h localhost -U dev -T tab1 -T tab2  -s -f dev.dump

pg_dump -h localhost -U prod -T tab1 -T tab2  -s -f prod.dump

利用apgdiff-2.4.jar工具进行两个文件的比对:

java -jar apgdiff-2.4.jar --ignore-start-with prod.dump dev.dump > diff.sql

最后在prod数据库上执行diff.sql文件就可以了。

4.注意

apgdiff-2.4.jar在apgdiff官网可以下载

在导出dump文件的时候使用-T参数是排除表,为什么不用-t指定导出那些表呢?使用-t参数生产的dump文件在进行比对时会报错:

 Exception in thread "main" java.lang.NullPointerException

at cz.startnet.utils.pgdiff.parsers.CommentParser.parseColumn(CommentParser.java:272)
at cz.startnet.utils.pgdiff.parsers.CommentParser.parse(CommentParser.java:46)
at cz.startnet.utils.pgdiff.loader.PgDumpLoader.loadDatabaseSchema(PgDumpLoader.java:202)
at cz.startnet.utils.pgdiff.loader.PgDumpLoader.loadDatabaseSchema(PgDumpLoader.java:239)
at cz.startnet.utils.pgdiff.PgDiff.createDiff(PgDiff.java:36)
at cz.startnet.utils.pgdiff.Main.main(Main.java:45) 

这可能是一个bug。Google一下解释是:

 as the new bug summary states now, apgdiff currently does not support setting comments on columns that are inherited from other tables, which means in your case that apgdiff fails when it cannot find column xxxx in table main, though it should take it from
main_parent where the column is defined. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: