Comparing two PostgreSQL databases -- order of pg_dump output

From: Joe Abbate <jma(at)freedomcircle(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Comparing two PostgreSQL databases -- order of pg_dump output
Date: 2011-08-30 19:07:22
Message-ID: 4E5D34EA.8030907@freedomcircle.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In order to compare the schema of two presumably identical databases,
I've been diffing the output of pg_dump -Osx. However, I've found that
the order of the output is not very reliable. For example, after
recreating the Pagila sample database, I find the following:

--- pagila.dmp 2011-08-26 14:34:48.000000000 -0400
+++ pagila.dev-dmp 2011-08-26 14:34:47.000000000 -0400
@@ -1140,7 +1140,7 @@
--

CREATE TRIGGER last_updated
- BEFORE UPDATE ON city
+ BEFORE UPDATE ON actor
FOR EACH ROW
EXECUTE PROCEDURE last_updated();

@@ -1160,7 +1160,7 @@
--

CREATE TRIGGER last_updated
- BEFORE UPDATE ON customer
+ BEFORE UPDATE ON category
FOR EACH ROW
EXECUTE PROCEDURE last_updated();
...

The same triggers exist on both databases, it's just that the order is
different (apparently they're output in creation order). This even more
crucial with PostGIS databases, which have several hundred function and
operator pairs where the only difference is one takes arguments of type
geometry and the other uses type geography. There the pg_dump diff
approach is nearly useless.

I thought that comparing database schemas would be quite desirable,
e.g., between development/test and production databases. Is there
perhaps some mechanism or tool that people use for this purpose, or is
this not a requirement?

Incidentally, these comparisons are for the Pyrseas tools I'm
developing. The output of dbtoyaml is predictable (not because of
anything I wrote, but because pyyaml outputs everything in alphabetical
order), and I can compare the YAML outputs quite nicely (however, it
doesn't show me things I haven't implemented yet, e.g., OPERATOR CLASSes
in the case of PostGIS).

Joe

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jaime Casanova 2011-08-30 19:24:14 Re: Comparing two PostgreSQL databases -- order of pg_dump output
Previous Message Peter Eisentraut 2011-08-30 18:58:58 symbol mismatches on minor version upgrades