简体   繁体   English

新主人的 POSTGRES 复制

[英]POSTGRES REPLICATION for new master

We are putting together an architecture to support High Availability for our Postgres 9.5 Database.我们正在整合一个架构来支持我们的 Postgres 9.5 数据库的高可用性。 We have 1 master and 3 slaves Replicating the data of the master.我们有 1 个 master 和 3 个 slave 复制 master 的数据。 When The master goes down Slave 1 is promoted to new master but Slave 2 and Slave 3 are still pointing to the previous master and not the updated master node.当主节点宕机时,从节点 1 被提升为新的主节点,但从节点 2 和从节点 3 仍然指向之前的主节点,而不是更新后的主节点。 Is there a way to make the slaves to read from the new master dynamically .有没有办法让奴隶从新的主人动态读取。 Or does it require changing the configurations manually and restarting the slaves?还是需要手动更改配置并重新启动从站?

There's no short answer, but I'll try:没有简短的答案,但我会尝试:

  • When primary server fails you'll promote one slave, and reconfigure all other slaves to target the new master.当主服务器出现故障时,您将提升一个从服务器,并重新配置所有其他从服务器以定位新的主服务器。 However there's one scenario in which reconfiguring other slaves might not be needed: if you are using "WAL archiving", and your archive is stored on a shared drive which survived the failure of the old primary.但是,在一种情况下,可能不需要重新配置其他从站:如果您使用“WAL 归档”,并且您的归档文件存储在共享驱动器上,该驱动器在旧主服务器出现故障后仍然存在。 If the new primary continues to use the same shared store you might not need to reconfigure other slaves.如果新的主服务器继续使用相同的共享存储,您可能不需要重新配置其他从服务器。 Again, I've never tried this - you can try.再说一次,我从来没有试过这个——你可以试试。
  • If your replication mechanism is based on "replication slots" (introduced in PostgreSQL 9.4) - then you have to reconfigure all the slaves.如果您的复制机制基于“复制槽”(在 PostgreSQL 9.4 中引入) - 那么您必须重新配置所有从站。 In this case actually you'll have to rebuild replication on all other slaves from scratch (as if they've never been slaves at all).在这种情况下,实际上您必须从头开始在所有其他从站上重建复制(就好像它们根本就不是从站一样)。 Nevertheless, in my opinion "replication slots" are better choice.尽管如此,在我看来“复制槽”是更好的选择。

Regarding automation: You've asked if it is possible to automatically reconfigure other slaves, but thing you've missed to mention is if you have any failover automation implemented.关于自动化:您已经询问是否可以自动重新配置其他从站,但您没有提到的是您是否实施了任何故障转移自动化。 What I'm trying to say is that PostgreSQL itself will not automatically perform failover (promote one of slaves when the master fails).我想说的是 PostgreSQL 本身不会自动执行故障转移(当主站失败时提升从站之一)。 At least you have to create "trigger file" on the slave to be promoted, and you have to do this manually or by using another product (for example pgpool2).至少您必须在要提升的从站上创建“触发文件”,并且您必须手动或使用其他产品(例如 pgpool2)来执行此操作。

If you use pgpool2 - you can setup automatic slave reconfiguration by setting follow_master_command pgpool.conf value.如果您使用 pgpool2 - 您可以通过设置 follow_master_command pgpool.conf 值来设置自动从属重新配置。

Finally I'll strongly recommend reading this tutorial - it'll make your life easier.最后,我强烈建议您阅读本教程- 它会让您的生活更轻松。

Edit : I've forgot to say two things:编辑:我忘了说两件事:

  • Automatically reconfiguring all other slaves as soon as the new master is promoted might not be a good idea, especially if you have many slaves.一旦新的 master 被提升,自动重新配置所有其他 slaves 可能不是一个好主意,特别是如果你有很多 slaves。 It'll put additional pressure on your new primary, and on your network, so in some cases it is better to postpone this for night hours for example.这会给您的新主服务器和网络带来额外压力,因此在某些情况下,最好将其推迟到夜间进行。 More on this in the mentioned tutorial.在提到的教程中详细介绍了这一点。
  • I've wrote the tutorial.我已经写了教程。

As e4c5 commented, you can use repmgr for managing this type of tasks.正如 e4c5 评论的那样,您可以使用 repmgr 来管理此类任务。 I have tried repmgr and I was done without a problem.我已经尝试过 repmgr 并且我没有问题地完成了。

I have followed a tutorial for doing that and here is the link:我已经按照教程进行了操作,这是链接:

http://jensd.be/591/linux/setup-a-redundant-postgresql-database-with-repmgr-and-pgpool http://jensd.be/591/linux/setup-a-redundant-postgresql-database-with-repmgr-and-pgpool

I hope following this tutorial you can do what you want without any problem.我希望按照本教程,您可以毫无问题地做您想做的事。

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

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