This project sets up a Postgres High Availability (HA) cluster with automatic failover using Docker and repmgr.
- Docker
- Docker Compose
- Initialize the Postgres HA cluster:
./pg_ha_init.sh
- Test the failover:
./pg_ha_failover.sh
- Cleanup the resources:
docker-compose down --remove-orphans -v
Q: How can I use docker-entrypoint.sh
to launch the Postgres database?
A: You can use the following command:
exec docker-entrypoint.sh postgres -D /var/lib/postgresql/data -c config_file=/etc/postgresql/postgresql.conf
Q: Why does the sequence ID become discontinuous after failover?
A: Changes to sequences are logged to the Write-Ahead Log (WAL) to allow recovery from a backup or after a crash. However, to optimize performance, not every call to nextval
is logged to the WAL. This means that after recovering from a crash, the sequence may have skipped some values, resulting in gaps in the sequence.
Q: What will happen if I don't specify the wal_keep_size
in postgresql.conf?
A: It means the system will not preserve any extra WAL files for standby purposes. You may encounter a WAL file missing error during the --force-rewind
process. It is better to specify a value based on the downtime period. 128MB
should be enough for a short period of downtime.