使用 dblink 在 PostgreSQL 中的数据库之间同步事务

发布于 2024-12-27 17:59:44 字数 206 浏览 2 评论 0原文

我想在两个数据库之间透明地同步一组表,而无需更改应用程序代码。我的想法是在源数据库表中创建插入、更新和删除触发器,以使用 dblink 将数据复制到目标。无缝数据库表。

问题在于源表中的更改始终在事务内完成。触发器会自动复制目标中的更改。表,但如果源事务回滚目标。表格变化则不然。

有没有办法在两个数据库之间自动同步事务开始和提交/回滚?类似触发器的行为将是理想的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多孤肩上扛 2025-01-03 17:59:44

是的,从很久以前就有可能 - 使用 Slony-I 或其他基于触发器的复制。

行更新被记录到“主”端的特殊表中,并在“从”端异步重播。

外部程序/守护进程用于同步更改。

请参阅http://www.postgresql.org/docs/current/ static/ different-replication-solutions.htmlhttp://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling#Replication 了解更多信息。

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.

羁客 2025-01-03 17:59:44

当 9.3 发布时,查看 http://www.postgresql.org/ docs/9.3/static/postgres-fdw.html。您可以回滚外部数据库中的事务。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文