简体   繁体   English

PostgreSQL 9.1自动故障转移

[英]Automatic failover with PostgreSQL 9.1

PostgreSql 9.1 has master-slave synchronous replication. PostgreSQL 9.1具有主从同步复制。 Suppose the master is machine A and the slave is machine B. 假设主机是机器A,从机是机器B。

If the master fails, how does PostgreSQL know when to make the slave the master? 如果主服务器发生故障,PostgreSQL如何知道何时使从服务器成为主服务器? What if the slave incorrectly thought the master was down because of a temporary network glitch on the master where the client program could still contact the master though. 如果从服务器错误地认为主服务器由于主服务器上的临时网络故障而关闭,该客户端程序仍然可以与主服务器联系,那该怎么办?

And moreover, how would my client program know the slave in the new master and more importantly is ready to accept writes. 而且,我的客户程序将如何知道新主服务器中的从服务器,更重要的是已准备好接受写入。 Does the slave send a message to the client? 从站是否向客户端发送消息?

检查repmgr ,它的工作之一就是解决这个问题。

Typically you want to use a promotion-management system like repmgr or patroni. 通常,您希望使用促销管理系统,例如repmgr或patroni。 Then you want to use some sort of a high availability proxy (could be pgbouncer or haproxy) to handle the actual abstraction so your applications do not need to know what system is master. 然后,您想使用某种类型的高可用性代理(可以是pgbouncer或haproxy)来处理实际的抽象,因此您的应用程序不需要知道哪个系统是主系统。

In answer to your question, most of these systems use a heartbeat to determine if there is a problem. 在回答您的问题时,大多数这些系统都使用心跳来确定是否存在问题。 Patroni goes out over the etcd heartbeat. Patroni在etcd的心跳上跳了出来。 Repmgr has its own heartbeat check. Repmgr有自己的心跳检查。 With Repmgr you need to write hook scripts to take care of stonith, and so forth. 使用Repmgr,您需要编写钩子脚本来处理stonith,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM