This repo it helps you quickly spin up a 3-node cluster of PostgreSQL, managed by Patroni using Consul.
When you start the cluster, you get 2 nodes (pg01 and pg02), each running:
- PostgreSQL
- Patroni
- Consul agent
and a third node (pg03) running:
- Consul (server)
- HAProxy
- pgBouncer
The connection/data path is the following:
- pgBouncer (where the app will connect)
- HAProxy
- PostgreSQL
All packages are from Ubuntu 16.04, except for PostgreSQL itself, which is at version 12.x.
The cluster is configured with a single primary and one asynchronous streaming replica.
- Virtualbox
- Vagrant
git clone https://github.com/vtomasr5/postgresql-patroni-setup.git
- On 3 separate windows:
vagrant up pg03 && vagrant ssh pg03 # pg03 contains the consul server and it must start first
vagrant up pg01 && vagrant ssh pg01
vagrant up pg02 && vagrant ssh pg02
Get patroni information from his members
patronictl -c /etc/patroni/patroni.yml list
You should use the pgBouncer connection pool
- 172.28.33.13:6432
But you can also connect via HAproxy using the balancing IP
- 172.28.33.13:5000 (postgresql)
- 172.28.33.13:7000 (HAProxy stats)
- Add pgBouncer support
- Test on a Windows host (tested on Linux and macOS hosts)
- Improve documentation
We're happy to receive questions as issues on this repo, so don't be shy!
It's hard to know exactly what documentation/guidance is useful to people, so we'll use the questions we answer to improve this README and link out to more places you can read up on the technologies we're using.