Node counts for a Postgres cluster, explained
What you get with 1 computer, 2, 2 plus a witness, or 3 or more in a CoyoteDB Postgres cluster, which setup we recommend, and good practice for any of them.
The number of computers you use decides what happens when one of them goes down. For a side-by-side comparison, see Recommended setups.
| Setup | What you get | If the main node goes down |
|---|---|---|
| 1 node | It works. No backup node. | The database is down until that computer is back. |
| 2 nodes | A live copy on the second computer. | No automatic switch-over: down until the main node is back. |
| 2 nodes + witness | A live copy, plus a tie-breaker. | The other node takes over automatically. |
| 3 or more nodes | Full copies on every node. | The others take over automatically. |
Which setup should I pick?
- 2 computers + a witness: recommended for most people. Two full copies and automatic switch-over. The witness holds no data and only votes. It can be any small always-on device: a mini PC, a Raspberry Pi, an old laptop that stays plugged in and awake, or a cheap cloud server, and it can run a different system from the data computers.
- 3 computers: recommended when the data really matters. Three full copies, automatic switch-over, and no witness needed. Even while one computer is down, a save still lands on two computers.
- 1 computer: for trying it out, development or a side project. Real Postgres, but no second copy. If that computer stops, the database stops.
- 2 computers, no witness: a live copy, no automatic switch-over. It works and keeps a live, full copy, but nothing switches over when the main computer dies. While both are up, you can move the main role yourself with
coyote switch --to <node>. Fine if you just want a live second copy; add a witness to make switch-over automatic.
More than three computers is possible. Keep the total number of voting machines odd (data computers plus any witness), so there is always a clear majority.
1 node
Good for trying CoyoteDB out, or for data you can live without for a while. It is real Postgres, but there is nowhere else for the data to be if this computer stops.
2 nodes
The second computer keeps a live copy. If the main node dies, your data is safe on the other one, but it will not take over by itself. Two nodes cannot out-vote each other, so the database is down until the main node is back. Add a witness to make switch-over automatic.
When only one data node is left
This applies to both 2-node setups, with or without a witness. When one data node is down, saves pause for about 30 seconds, then carry on using the node that is left. Until the other node is back and caught up, there is no second copy of new saves, and CoyoteDB shows a clear warning.
If you would rather have saves wait than run on one copy, an optional stricter setting does that. The trade-off: your app cannot save until a second node is back.
2 nodes + a witness
A witness is a tiny helper that holds no data and only votes. It can run on any system type, even if your data nodes are all one type. With a witness, the two data nodes plus the witness make three votes, so switch-over can happen on its own.
3 or more nodes
Every data node has a full copy. If any one goes down, the rest still have a majority, vote in a new main node if needed, and carry on. With three data nodes, losing one still leaves two, so saves keep landing on two nodes.
A rule for every setup
All data nodes in one cluster must be the same system type: all Windows, or all Linux, or all Mac with the same chip family. The witness and the apps that connect can be anything.
Good practice
These follow from how CoyoteDB works, whichever setup you pick.
- Same system type for data computers. All Windows, all Linux, or all Mac with the same chip family. The witness and your apps can be anything.
- Use computers that stay on. A laptop that sleeps is a poor cluster member. It is fine as a single node for development.
- A private network that always connects. Put the computers on a private network where they can always reach each other: Tailscale, Twingate, a site-to-site VPN (for example UniFi), or the same LAN. Nodes talk over one encrypted port. See Running Postgres over Tailscale or a VPN.
- Not everything on one power strip or one internet line. If you can, put the witness in a different place, or on a small cloud server, so one power cut or one router failure cannot take out the majority.
- Steady links. Wired or solid Wi-Fi beats flaky links. The nodes check on each other all the time.
- Keep backups as well. Copies between nodes protect you from a dead computer, not from a deleted table: a mistake is copied to every node at once. See Why you still need backups.
- Know what happens with one data computer left. Saves pause for about 30 seconds, then carry on with a clear warning until the other computer is back.