1

I would like to sync a set of tables between two databases, transparently without application code chages. My idea is to create triggers on insert, update and delete, in the source database tables to replicate the data using dblink to the dest. database tables seamlessly.

The problem is that changes in the source tables are always done inside a transaction. The triggers automatically replicate changes in the dest. tables but if the source transaction is rolled back the dest. tables changes are not.

Is there a way to automatically sync transaction begin and commit/rollback between the two databases? A trigger-like behavior would be ideal.

2 Answers 2

1

Yes, it's possible from ages - using Slony-I, or other trigger-based replication.

Row updates are logged to special tables on "master" side, and replayed asynchronously on "slave" side.

External program/daemon is used to synchronise changes.

See http://www.postgresql.org/docs/current/static/different-replication-solutions.html and http://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling#Replication for more information.

Sign up to request clarification or add additional context in comments.

Comments

1

When 9.3 comes out, check out http://www.postgresql.org/docs/9.3/static/postgres-fdw.html. You can roll back transactions in foreign databases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.