Re: sync structures

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Subject: Re: sync structures
Date: 2009-09-28 16:55:51
Message-ID: 0AC70FAF-A5A1-4F7C-ACFC-3B94B55079E0@blighty.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Sep 28, 2009, at 9:24 AM, John wrote:

> On Monday 28 September 2009 09:06:25 am Filip Rembiałkowski wrote:
>> 2009/9/28 John <jfabiani(at)yolo(dot)com>
>>
>>> Hi,
>>> I have a development DB and a production DB. I need a way to sync
>>> the
>>> changes
>>> I make to the stucture in the devel DB to the production DB. I
>>> found
>>> pgdiff
>>> but can't get it to work. I would like a solution that would work
>>> on
>>> windows
>>> and linux. But I'll take either alone.
>>>
>>> postgres 8.3
>>> openSUSE 11.0
>>> windows XP/vista
>>>
>>> Thanks in advance for any help.
>>
>> You could use standard text compare programs. They won't write a
>> patch for
>> you. There's still some niche for live DBAs.
>>
>> pg_dump -sOx dev_db_name > dev.schema
>> pg_dump -sOx prod_db_name > prod.schema
>> diff -u dev.schema prod.schema
>
> Thanks that will help. After all this time I'm surprized that
> someone hasn't
> provide an easy way to get this done. It's has to be every developers
> problem.

It's hard to do by comparing two schemas in general. For example,
if you rename a column from bob to jerry, there's not enough information
left to a tool to tell whether you dropped a column called bob and
created one called jerry, or renamed bob to jerry.

If you choose a more appropriate format than straight DDL, it's fairly
easy to do this sort of thing entirely mechanically.

Three links I have handy are ...

http://xml2ddl.berlios.de/
http://dbmstools.sourceforge.net/
http://www.liquibase.org/

... but there are a bunch of other similar tools too.

They'll all pull from existing databases too, so they can also be
used to diff existing schemas with some slight limitations.

Another approach is to store all your schema versions as
upgrade (and downgrade) scripts, rather than as whole DDL
scripts. Everything else you need can be derived from those
mechanically. It also lets you be a lot smarter about how to
handle existing data when changing a schema.

Cheers,
Steve

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2009-09-28 16:56:33 Re: sync structures
Previous Message Thom Brown 2009-09-28 16:49:33 Functions returning multiple rowsets