
点击蓝字关注我们
一
介绍
EDB 故障转移管理器 (EFM) 是一种用于管理 Postgres 数据库集群的工具,可使用流复制实现主备部署架构的高可用性。虽然将EFM与异步备用服务器一起使用是一种常见做法并且非常简单,但您也可以在具有多个同步备用服务器的环境中有效地使用EFM,而无需在每次发生故障转移时进行手动干预。
二
同步流复制方式运行EFM
在过去几年中,EFM 添加了许多新功能,使其能够在发生故障转移或手动切换时无缝维护同步流副本。当使用efm promote efm -switchover 执行手动切换时,EFM能够使用主数据库上的 synchronous_standby_names和备用数据库上的application_name等配置参数,无缝地重新配置EFM集群中存在的旧主数据库或任何其他备用数据库,以便作为同步副本重新连接到新的主数据库。但是,仍然需要手动重建故障节点(类似于异步模式下的自动故障转移场景),因为在故障转移的情况下,旧的主服务器可能会偏离备用服务器的状态,并且无法赶上复制。
下面展示了配置同步副本的简单切换场景。
测试用例中,使用 EFM 4.7和PostgreSQL 15,在Ubuntu 22.04 上运行。EFM 集群有 3 个节点(1 个主节点和 2个同步备用节点)。
root@ip-172-31-1-92:~# usr/edb/efm-4.7/bin/efm cluster-status efmCluster Status: efmAgent Type Address DB VIPStandby 172.31.0.255 UPPrimary 172.31.1.92 UPStandby 172.31.14.240 UPAllowed node host list:172.31.14.240 172.31.1.92 172.31.0.255Membership coordinator: 172.31.14.240Standby priority host list:172.31.14.240 172.31.0.255Promote Status:DB Type Address WAL Received LSN WAL Replayed LSN InfoPrimary 172.31.1.92 0/11014FF8Standby 172.31.0.255 0/11014FF8 0/11014FF8Standby 172.31.14.240 0/11014FF8 0/11014FF8Standby database(s) in sync with primary. It is safe to promote.
root@ip-172-31-1-92:~# psql postgres postgres -c "show synchronous_standby_names;"synchronous_standby_namesANY 2(pg1, pg2, pg3)(1 row)
root@ip-172-31-1-92:~# psql postgres postgres -c "select pid, usename, application_name, client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, sync_priority, sync_state FROM pg_stat_replication;"pid | usename | application_name | client_addr | state | sent_lsn | write_lsn | flush_lsn | replay_lsn | sync_priority | sync_state4100 | postgres | pg2 | 172.31.14.240 | streaming | 0/11014FF8 | 0/11014FF8 | 0/11014FF8 | 0/11014FF8 | 1 | quorum4102 | postgres | pg3 | 172.31.0.255 | streaming | 0/11014FF8 | 0/11014FF8 | 0/11014FF8 | 0/11014FF8 | 1 | quorum(2 rows)
根据上述配置,如果 3 个备用数据库中至少有 2 个连接到数据库,则数据库将继续处理事务。在当前情况下,pg2和pg3作为同步备用节点连接到它,pg1是主节点本身的名称,在 EFM 配置文件中配置。
root@ip-172-31-1-92:~# grep ^application.name etc/edb/efm-4.7/efm.propertiesapplication.name=pg1
当发生故障转移并且该节点尝试连接回新的主服务器时,它可能会使用主服务器期望的应用程序名称。
当发生切换且参数auto.reconfigure设置为true时,EFM通过配置文件并根据提供的值使用application_name、 restore_command等参数重新配置备用服务器。
root@ip-172-31-1-92:~# grep ^restore.command etc/edb/efm-4.7/efm.propertiesrestore.command=scp postgres@%h:/var/lib/postgresql/15/archive/%f %p
root@ip-172-31-1-92:~# grep ^application.name etc/edb/efm-4.7/efm.propertiesapplication.name=pg1
root@ip-172-31-1-92:~# grep ^auto.reconfigure etc/edb/efm-4.7/efm.propertiesauto.reconfigure=true
#The other important parameter that is required to be configured in the postgresql configuration file (synchronous_standby_names).
root@ip-172-31-1-92:~# grep ^synchronous_standby_names etc/postgresql/15/main/postgresql.auto.confsynchronous_standby_names = 'ANY 2(pg1, pg2, pg3)'
执行手动切换:
root@ip-172-31-1-92:~# usr/edb/efm-4.7/bin/efm promote efm -switchoverPromote/switchover command accepted by local agent. Proceeding with promotion and will reconfigure original primary. Run the 'cluster-status' command for information about the new cluster state.root@ip-172-31-1-92:~# /usr/edb/efm-4.7/bin/efm cluster-status efmCluster Status: efmAgent Type Address DB VIPPrimary 172.31.0.255 UPStandby 172.31.1.92 UPStandby 172.31.14.240 UPAllowed node host list:172.31.1.92 172.31.0.255 172.31.14.240Membership coordinator: 172.31.1.92Standby priority host list:172.31.1.92 172.31.14.240Promote Status:DB Type Address WAL Received LSN WAL Replayed LSN InfoPrimary 172.31.0.255 0/200001B8Standby 172.31.1.92 0/200001B8 0/200001B8Standby 172.31.14.240 0/200001B8 0/200001B8Standby database(s) in sync with primary. It is safe to promote.
有关如何设置新 EFM 集群的详细信息,请参阅
https://www.enterprisedb.com/docs/efm/latest/04_configuring_efm/文档。
要查找有关如何配置同步备用副本的详细信息,请参阅
https://www.postgresql.org/docs/current/warm-standby.html#SYNCHRONOUS-REPLICATION

感谢您关注新智锦绣科技(北京)有限公司!作为 Elastic 的 Elite 合作伙伴及 EnterpriseDB 在国内的唯一代理和服务合作伙伴,我们始终致力于技术创新和优质服务,帮助企业客户实现数据平台的高效构建与智能化管理。无论您是关注 Elastic 生态系统,还是需要 EnterpriseDB 的支持,我们都将为您提供专业的技术支持和量身定制的解决方案。
欢迎关注我们,获取更多技术资讯和数字化转型方案,共创美好未来!
![]() | ![]() |
Elastic 微信群 | EDB 微信群 |

发现“分享”和“赞”了吗,戳我看看吧






