From: Reece Hart <reece@in-machina.com>
To: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: compare two databases
Date: Mon, 17 Nov 2003 09:51:55 -0800
Message-ID: <1069091514.2618.23.camel@tallac> (raw)
In-Reply-To: <20031117165145.GS1716@libertyrms.info>
References: <3FB78506.9080509@net6d.com>
<Pine.LNX.4.44.0311160943160.812-100000@atg2000.itc.virginia.edu>
<20031117165145.GS1716@libertyrms.info>
You might consider comparing the schemas with pg_dump -s and diff (as
was already suggested), then comparing the data with a (e.g.) perl DBI
script connected to two databases simultaneously.
If the two databases are truly descended from the same design (e.g.,
restored from the same dump), then I'd expect the dump order to be the
same and the diff probably won't be corrupted with false differences.
I'd strip lines matching /^--/ to facilitate the diff.
A simple-minded implementation (I excel here) of the perl-DBI part
doesn't require table-specific code. I'd do it like this: 1) connect to
both databases; 2) for each (common) table, create a statement which
selects rows in some canonical order (e.g., sorted by primary key or
some non-degenerate multi-column tuple), and then fetch into a hash
one-by-one (cursors would be better, but IIRC the DBI code doesn't
support them). Because you're fetching into a hash, you can write a
single routine to compare all elements of the common hash keys (you'll
already know of differences between keys/columns themselves from the
schema diff). This is not the speed-optimal solution, but it shouldn't
be too bad in total time and you'd probably spend even more time
implementing the optimal solution.
Obviously, this will miss certain diabolical changes like column or
table renames, but it should suffice for most mutations of two instances
from a common schema and content.
-Reece
--
Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: reece@in-machina.com
Subject: Re: compare two databases
In-Reply-To: <1069091514.2618.23.camel@tallac>
References: <3FB78506.9080509@net6d.com> <Pine.LNX.4.44.0311160943160.812-100000@atg2000.itc.virginia.edu> <20031117165145.GS1716@libertyrms.info> <1069091514.2618.23.camel@tallac>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox