如何在Postgres同步复制中禁用无通用的读取



我已经设置了使用同步复制的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

我可以更改其行为以仅返回同步投入数据吗?

相关的未解决问题:

  • http://comments.gmane.org/gmane.comp.db.postgresql.devel.general/194555

相关代码:

  • https://github.com/postgres/postgres/blob/1d25779284fe1ba08ecd57e647292a9deb241376/src/src/backend/backend/backend/backend/replation/replication/replication/syncrep.c#l251

它是现在的功能的缺点,就像克雷格·里格(Craig Riger)所解释的那样。

请注意,只有一个备用备用的同步复制设置,即备用的位置,应视为下降或功能失调。这就是为什么您至少需要两个同步待机服务器,如果您不想降低您的可用性。

最新更新