question

My Damus avatar image
My Damus asked

Merging two databases in Postgre SQL

I would like to merge two different databases with some common tables exists in both. Can we merge these two databases without changing the code in my application?
postgresql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
If the tables have the same names between the two databases and the databases will be identical after the merge, perhaps you could change the configuration file for your application to only use a single database. This should not necessitate a code change. If you need to continue to use both database, it will depend largely on how your application use the databases. If the tables you will be removing from one database are read-only from the application, you should have a pretty good chance using [dblink][1] (sort of the PostgreSQL version of opendatasource) and replacing the missing tables with views of the same name. If your application writes to the tables you will be removing, the complexity goes up a bit. In addition to views and dblink, you will need to implement [rules on insert, update, and delete][2] to take care of data modifications. I haven't actually implemented either of these scenarios. You can do some further reading on the University of Washington's Network Management Tools [blog][3] about their experience with it. I would also recommend a visit to some [PostgreSQL forums][4] for additional implementation help. [1]: http://www.postgresql.org/docs/8.3/static/contrib-dblink.html [2]: http://www.postgresql.org/docs/8.3/interactive/rules-update.html [3]: http://tools.cac.washington.edu/2010/01/postgresql-fun-cross-database-joins.html [4]: http://www.bing.com/search?q=postgresql+forums
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

My Damus avatar image My Damus commented ·
Thanks KenJ, after merging I have to use one database only.
0 Likes 0 ·
KenJ avatar image KenJ commented ·
It sounds like you should be fine with just the configuration change. If you have a place to test the change prior to production, that would be ideal.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.