pg cluster with only 2 machine

hi guys, i just scale up horizontally my pg VM from 1 machine to 2 machine, then i saw a new message pop up:


after some digging on google, i realize having 3 machines is the requirement to achieve high availability (HA).

but what if i really only want 2 machine to achieve HA? i don’t mind if it is a read replica.

Currently am having 2 machines in 1 region, so 1 machine appear to be “Primary” and another 1 is “Replica”. is this already considered HA? or there are still steps i need to take in order to achieve HA? Am worry that the database crashes and data loss.

definitely, am quite a beginner, please correct me, or advise me. Thanks in advance!

NOTE:
my understanding/knowledge is that,

  • read replica = same data from primary replica, but read only, no write.
  • primary replica = capable of read and write data.
  • If primary replica goes down, read replica will take over and become primary.
    Please correct me if am wrong.
  • A long time Flyio fan.

You need at least 3 machines to achieve HA. I don’t think that currently there is a painless setup for 2 with repmgr (using fly-apps/postgres-flex).

Currently a 2 replicas + witness setup is not fully implemented, it seems the work have stalled in march 2023: Figure out the Witness node UX · Issue #175 · fly-apps/postgres-flex · GitHub

Currently you do need 3 replicas for automatic failover. I think with 2 replicas you could still do manual failover (haven’t tested this), but with only 2 machines voting they can never be sure they are the only leader.

And just in case, because it’s easy to get this mixed up: replication helps with scaling and with recovery from machine failure, but it’s not enough to prevent data loss. You will still need backups too.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.