X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B4D1FD1BA81 for ; Mon, 17 Nov 2003 17:52:32 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 16386-05 for ; Mon, 17 Nov 2003 13:52:02 -0400 (AST) Received: from ohm.gene.com (fw-open-virt.gene.com [192.12.78.250]) by svr1.postgresql.org (Postfix) with ESMTP id 31C05D1B53A for ; Mon, 17 Nov 2003 13:52:01 -0400 (AST) Received: from tallac.gene.com (tallac.gene.com [128.137.116.213]) by ohm.gene.com (Switch-3.1.0/Switch-3.1.0) with ESMTP id hAHHpucI028556 for ; Mon, 17 Nov 2003 09:51:56 -0800 (PST) Received: by tallac.gene.com (Postfix, from userid 13922) id 30E3E4B2C8; Mon, 17 Nov 2003 09:51:55 -0800 (PST) Subject: Re: compare two databases From: Reece Hart To: pgsql-admin In-Reply-To: <20031117165145.GS1716@libertyrms.info> References: <3FB78506.9080509@net6d.com> <20031117165145.GS1716@libertyrms.info> Content-Type: multipart/alternative; boundary="=-MUDjqTDEItLRtyJ6+8HJ" Message-Id: <1069091514.2618.23.camel@tallac> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Mon, 17 Nov 2003 09:51:55 -0800 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/313 X-Sequence-Number: 11300 --=-MUDjqTDEItLRtyJ6+8HJ Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-MUDjqTDEItLRtyJ6+8HJ Content-Type: text/html; charset=utf-8 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
--=-MUDjqTDEItLRtyJ6+8HJ--