标签: two-phase-commit

在 Postgres 上使用两阶段提交

假设“db1”中有一个名为“t1”的表,“db2”中有一个名为“t2”的表,我需要在两个表上插入一条记录,否则会失败。

连接到 db1,我想我应该输入以下内容:

BEGIN;
PREPARE TRANSACTION 'pepe'; -- this says the manual that makes your transaction gets stored on disk, so what is the purpose if I can't use it from another database?)

insert into t1 (field) values ('a_value');

COMMIT PREPARED 'pepe'
Run Code Online (Sandbox Code Playgroud)

连接到db2,我猜:

BEGIN;
PREPARE TRANSACTION 'pepe'; -- this fails (the name of the transaction, what is the meaning, what is use for?)
 -- It complains about this "ERROR:  transaction identifier "pepe" is already in use"

insert into t2 (field) …
Run Code Online (Sandbox Code Playgroud)

postgresql two-phase-commit

7
推荐指数
1
解决办法
8348
查看次数

2PC(2 阶段提交)和 2 PL(2 阶段锁定)之间的区别

两者有什么区别?表面上的协议看起来不同,但我想了解两者之间真正的不同之处以及为什么它们不等效。

database distributed paxos two-phase-commit

5
推荐指数
1
解决办法
2967
查看次数