我已经使用同步复制设置了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
然后新的,只有本地提交的值会显示在查询中!
postgres=# select * from test;
id | value
----+--------
1 | value2
为什么?
为什么Postgres允许我阅读一些未写入至少2台机器的内容,因为我配置了它?我希望阅读旧数据value1
。
我可以更改其行为以仅返回同步提交的数据吗?
相关未回答的问题:
相关代码:
答案 0 :(得分:2)
正如现在一样,这是该功能的一个缺点,就像Craig Riger解释的那样。
请注意,只有一个备用数据库处于关闭状态的备用数据库的同步复制设置将被视为关闭或功能失常。这就是为什么如果你不想减少你的可用性,你需要至少两个同步备用服务器。