Postgres pg_dump每次以不同的顺序转储数据库 [英] Postgres pg_dump dumps database in a different order every time

查看:189
本文介绍了Postgres pg_dump每次以不同的顺序转储数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个PHP脚本(它也使用linux bash命令),它将通过执行以下操作来运行测试用例:



我使用一个PostgreSQL数据库8.4.2)...



1。)创建一个DB
2.)修改DB
3.)存储数据库转储DB(pg_dump)



4。)通过执行步骤1.)和2.)进行回归测试,然后进行另一个数据库转储,原始数据库转储从步骤3)。



但是,我发现pg_dump不会总是以相同的方式转储数据库。它会每次以不同的顺序转储东西。因此,当我对两个数据库转储执行diff时,比较会导致两个文件不同,但实际上是相同的,只是顺序不同。



有不同的方式我可以去做pg_dump吗?



谢谢!

解决方案

不可能强制pg_dump以任何特定顺序转储数据,因为它以磁盘顺序转储数据 - 这种方式更快。<​​/ p>

您可以对pg_dump使用-a -d选项,然后使用排序输出,但数据中的换行符将使排序的输出无法导入。但是,对于基本比较,如果有什么改变,就足够了。


I am writing a PHP script (which also uses linux bash commands) which will run through test cases by doing the following:

I am using a PostgreSQL database (8.4.2)...

1.) Create a DB 2.) Modify the DB 3.) Store a database dump of the DB (pg_dump)

4.) Do regression testing by doing steps 1.) and 2.), and then take another database dump and compare it (diff) with the original database dump from step number 3.)

However, I am finding that pg_dump will not always dump the database in the same way. It will dump things in a different order every time. Therefore, when I do a diff on the two database dumps, the comparison will result in the two files being different, when they are actually the same, just in a different order.

Is there a different way I can go about doing the pg_dump?

Thanks!

解决方案

It is impossible to force pg_dump to dump data in any particular order, as it dumps data in disk order - it is much faster this way.

You can use "-a -d" options for pg_dump and then "sort" output, but newlines in data will make sorted output not importable. But for basic comparison whether anything changed it would suffice.

这篇关于Postgres pg_dump每次以不同的顺序转储数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆