Updating PostgreSQL schema with schema dump

Go To StackoverFlow.com

0

I have two servers: production and testing. Both of them run PostgreSQL. I made a lot of alterations on testing server, like ALTER table, CREATE INDEX etc. and want to transfer these alterations to the production server as easy as possible. What is the most convenient way for this?

2012-04-05 15:24
by Dmitriy Berkutov
This is PostgreSql, amirite? ... No, I think you mean http://software.fionet.com/pSQL/ - NoName 2012-04-05 15:25
Yes, it's PostgreSq - Dmitriy Berkutov 2012-04-06 10:15


2

The best way to do this would be:

  1. Run pgdump on each database, creating a full dump.
  2. Use a comparison tool like Beyond Compare to run through the two files side by side and create a merge; given that you've said there are only 'alter' changes and data changes the two should be similar enough that it can line them up
  3. Create a new test DB to deploy that script to, and run the script via psql (or whatever tool you use.)
  4. If that script runs successfully, wipe out the target DB and run that script against it.
  5. Make sure the application(s) that the DB backs are put offline during this process, at least during the time when you drop the DB and redeploy.
  6. If there are additional data changes, you may wish to pgdump the target DB before dropping it. You can then merge back in the data added during the time between the first pgdump on the target DB and the second one.

Other notes:

  • Pgdump is a command line tool, usually run via ssh (like PuTTY)
  • It outputs ASCII text SQL scripts in proper creation order, since PostGre can have object interdependencies.
  • psql, the command line interface to PostGre should allow you to execute a script from file, if you don't have a GUI program that can handle a SQL script as large as your entire dump.
  • There are options to dump data and structure separately.
2012-04-06 12:25
by NoName
Thank you for guidelines. I've come over the special posgtresql diff tool: http://apgdiff.startnet.biz/diff_online.ph - Dmitriy Berkutov 2012-04-06 14:17
@RiverC How do create full dump on Postgresql - Tomasz Waszczyk 2014-08-02 22:15
Ads