我已经使用同步复制设置了PostgreSQL 9.5,请参阅:
postgres=# show synchronous_commit;
synchronous_commit
--------------------
on
假设我有
postgres=# select * from test;
id | value
----+--------
1 | value1
然后,如果我关闭同步待机并发出
update test set value = 'value2' where id = 1;
它挂起(因为备用数据库没有确认它),正如预期的那样 .
但是,如果我现在按Ctrl-C,我会得到:
^CCancel request sent
WARNING: canceling wait for synchronous replication due to user request
DETAIL: The transaction has already committed locally, but might not have been replicated to the standby.
UPDATE 1
然后 the new, only locally committed value shows up in queries!
postgres=# select * from test;
id | value
----+--------
1 | value2
这是为什么?
为什么Postgres允许我阅读一些未写入至少2台机器的东西?我期望阅读旧数据, value1
.
我可以更改其行为以仅返回同步提交的数据吗?
相关未回答的问题:
相关代码:
1 回答
正如Craig Riger解释的那样,这是现在的功能的缺点 .
请注意,只有一个备用数据库处于关闭状态的备用数据库的同步复制设置将被视为关闭或功能失常 . 那是's why you need at least two synchronous standby servers if you don'吨想减少你的可用性 .