#!/bin/sh    
# 
# **********
# compare_pgbench_dumps
# **********
TMPOUT=/tmp/output.$$
DB1=$1    # First database
DB2=$2    # Second database

echo -n "**** comparing databases $DB1 and $DB2 ... "
psql -o dump.tmp.1.$$ $DB1 <<_EOF_
	select 'accounts:'::text, aid, bid, abalance, filler
			from accounts order by aid;
	select 'branches:'::text, bid, bbalance, filler
			from branches order by bid;
	select 'tellers:'::text, tid, bid, tbalance, filler
			from tellers order by tid;
	select 'history:'::text, tid, bid, aid, delta, mtime, filler,
			seqno from history order by seqno;
_EOF_
psql -o dump.tmp.2.$$ $DB2 <<_EOF_
	select 'accounts:'::text, aid, bid, abalance, filler
			from accounts order by aid;
	select 'branches:'::text, bid, bbalance, filler
			from branches order by bid;
	select 'tellers:'::text, tid, bid, tbalance, filler
			from tellers order by tid;
	select 'history:'::text, tid, bid, aid, delta, mtime, filler,
			seqno from history order by seqno;
_EOF_

if diff dump.tmp.1.$$ dump.tmp.2.$$ >test_1.diff ; then
	echo "success - databases are equal."
	rm dump.tmp.?.$$
	rm test_1.diff
else
	echo "FAILED - see test_1.diff for database differences"
fi
