473,473 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

db schema diff

Hi!

Suppose I have "pg_dump -s" of two pg installs, one is "dev", another is
"production". Their schemas don't differ too much, and I want to get a "diff
-u"-like schema diff so I can quickly add missing/remove old
tables/sequences/etc to one or another (manually). Is there some quick tool
for doing this ?

There was a thread about it sometime in aug, 2002, but it ended without
producing anything useful.

--
Best regards,
Igor Shevchenko

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
6 6428
> Suppose I have "pg_dump -s" of two pg installs, one is "dev", another
is "production". Their schemas don't differ too much, and I want to
get a "diff -u"-like schema diff so I can quickly add missing/remove
old
tables/sequences/etc to one or another (manually). Is there some quick
tool for doing this ?

There was a thread about it sometime in aug, 2002, but it ended without
producing anything useful.


This is the closest I get, but it is only marginally useful:

--File: pg_compare --------------------------------------
#!/bin/bash
# Script to dump a PostgreSQL database schema for two databases
# and compare them.
# Author: Berend M. Tober <btober@computer dot org>
# Date: August 25, 2003

PG_DUMP=/usr/bin/pg_dump
DIFF=/usr/bin/diff
GREP=/bin/grep
CAT=/bin/cat

-- 5434 is the port on which DEV runs
-- 5433 is the port on which QAT runs

${PG_DUMP} -s -p 5432 mydb|${GREP} -v '^--'|${CAT} -s >5432.sql
${PG_DUMP} -s -p 5433 mydb|${GREP} -v '^--'|${CAT} -s >5433.sql
${PG_DUMP} -s -p 5434 mydb|${GREP} -v '^--'|${CAT} -s >5434.sql

${DIFF} 5432.sql 5433.sql > 5432-5433.diff
${DIFF} 5433.sql 5434.sql > 5433-5434.diff
~Berend Tober


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2
On Monday 12 April 2004 22:38, you wrote:
${PG_DUMP} -s -p 5432 mydb|${GREP} -v '^--'|${CAT} -s >5432.sql
${PG_DUMP} -s -p 5433 mydb|${GREP} -v '^--'|${CAT} -s >5433.sql
${PG_DUMP} -s -p 5434 mydb|${GREP} -v '^--'|${CAT} -s >5434.sql

${DIFF} 5432.sql 5433.sql > 5432-5433.diff
${DIFF} 5433.sql 5434.sql > 5433-5434.diff


I used to do exactly this but the pg_dump order is different on my two
servers, and this generates lots of false diffs.

Here's a link to my really simple script which does what I want:
http://carcass.ath.cx/diffpg.pl

It doesn't honor schema and object ownership.

--
Best regards,
Igor Shevchenko

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3
Igor Shevchenko <ig**@carcass.ath.cx> writes:
On Monday 12 April 2004 22:38, you wrote:
${PG_DUMP} -s -p 5432 mydb|${GREP} -v '^--'|${CAT} -s >5432.sql
${PG_DUMP} -s -p 5433 mydb|${GREP} -v '^--'|${CAT} -s >5433.sql
${PG_DUMP} -s -p 5434 mydb|${GREP} -v '^--'|${CAT} -s >5434.sql

${DIFF} 5432.sql 5433.sql > 5432-5433.diff
${DIFF} 5433.sql 5434.sql > 5433-5434.diff
I used to do exactly this but the pg_dump order is different on my two
servers, and this generates lots of false diffs.


FWIW, CVS tip pg_dump has been modified to produce a consistent (and
safe) dump order, so its output should be a lot more useful for schema
diff'ing purposes than previous releases were.

It should work to build a current snapshot and use its pg_dump against
older servers, if you need a solution now.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #4
Jeremiah Jahn <je******@cs.earlham.edu> writes:
Although now consistent, is there a way to strip out the comments? since
they differ between dbs?


Not any more they don't ... unless you use the --verbose option,
pg_dump's comments should look the same too.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #5
Although now consistent, is there a way to strip out the comments? since
they differ between dbs? Right now, I use grep, but I have this need to
live in a perfect world were everything is just a command line
option..:)

On Mon, 2004-04-12 at 16:57, Tom Lane wrote:
Igor Shevchenko <ig**@carcass.ath.cx> writes:
On Monday 12 April 2004 22:38, you wrote:
${PG_DUMP} -s -p 5432 mydb|${GREP} -v '^--'|${CAT} -s >5432.sql
${PG_DUMP} -s -p 5433 mydb|${GREP} -v '^--'|${CAT} -s >5433.sql
${PG_DUMP} -s -p 5434 mydb|${GREP} -v '^--'|${CAT} -s >5434.sql

${DIFF} 5432.sql 5433.sql > 5432-5433.diff
${DIFF} 5433.sql 5434.sql > 5433-5434.diff

I used to do exactly this but the pg_dump order is different on my two
servers, and this generates lots of false diffs.


FWIW, CVS tip pg_dump has been modified to produce a consistent (and
safe) dump order, so its output should be a lot more useful for schema
diff'ing purposes than previous releases were.

It should work to build a current snapshot and use its pg_dump against
older servers, if you need a solution now.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

--
Jeremiah Jahn <je******@cs.earlham.edu>
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #6
by comments, I mean these:

--
-- TOC entry 16 (OID 166152808)
-- Name: user_credit_card; Type: TABLE; Schema: public; Owner: copa
--

these have really gone away in a new version, and if so, which one..?

On Wed, 2004-04-14 at 10:26, Tom Lane wrote:
Jeremiah Jahn <je******@cs.earlham.edu> writes:
Although now consistent, is there a way to strip out the comments? since
they differ between dbs?


Not any more they don't ... unless you use the --verbose option,
pg_dump's comments should look the same too.

regards, tom lane

--
Jeremiah Jahn <je******@cs.earlham.edu>
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: inquirydog | last post by:
Hi- I am using xml to hold configuration data for a project, and using schema to define what the configuration file should look like. I wanted to get some advice on an intelligant way to...
0
by: sfsfsfsf | last post by:
SchemaCrawler is a new schema diff tool on Sourceforge. http://sourceforge.net/projects/schemacrawler It can display the schema in a text format (plain text, CSV, or HTML), designed for...
1
by: aj | last post by:
DB2 v8 FP5 Red Hat AS 2.1 We are encountering a strange error where the default schema name that is specified w/ a SET SCHEMA command is being inconsistently ignored, causing all table...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
3
by: Thyagu | last post by:
Hi, I'd like to reverse engineer the schema definitions in the SQL Server on a daily basis and store them in a version control system. Could anyone please let know if there are any tools to...
13
by: Ilias Lazaridis | last post by:
I have implemented a simple schema evolution support for django, due to a need for a personal project. Additionally, I've provided an Audit: http://case.lazaridis.com/wiki/DjangoAudit As a...
2
by: zwasdl | last post by:
I'm using access to connect to Oracle via ODBC. I can also connect to Oracle via sql*plus. Can I write a query to join tables from different schema? If so, how? Thanks a million! Wei
6
by: Aaron Gray | last post by:
Hi, I am working on an HTML WYSISYG Wiki and need to display a diff page like WikiPedia does if two people edit a file at the same time to give the second user the diff. Basically with additions...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.