Scale down postgres cluster size

Do I need to do anything special with postgres if I want to remove a read replica? I currently have a primary with two read replicas. I want to remove one of the read replicas. Do I just destroy one of the read replica machines?

@dmaksimov It would depend on what PG implementation you’re running.

If you’re running on PG Flex, you need to maintain at least 3 members to meet quorum for HA. If you’re running on Stolon, you can get away with running 2 members given its architecture.

Assuming you’re not running a fork, you can verify which image you’re running with:

fly image show --app <app-name>

I’m using PG flex which created 3 machines automatically. Is it possible to just use 1 read replica?

But also, let’s say I went with the default 3 machines and added another. What would I do if I wanted to remove that extra one?

I’m using PG flex which created 3 machines automatically. Is it possible to just use 1 read replica?

If you run two in-region members, you’re cluster will go read-only whenever your replica gets rebooted as it won’t be able to meet quorum.

If you do not care about HA and just want to run a single read-replica, you can clone your primary into a nearby region. As long as the replica isn’t within your primary region, it won’t be considered for HA and won’t cause any problems.

But also, let’s say I went with the default 3 machines and added another. What would I do if I wanted to remove that extra one?

You would need to stop the machine and then remove it.

  # Stop 
 flyctl machines stop <machine-id> --app <app-name>
  
 # Remove
 flyctl machines remove <machine-id> --app <app-name>

It’s important to note that stopping the machine alone will not remove the member from the cluster. This is important if you’re looking to move from a 3 node cluster to a single node.

Gotcha, ok. So what would I do if I did want to scale a 3 node cluster to a single node?

You would just stop and remove the machines tied to your replicas and the cluster will adjust the quorum requirements accordingly.

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