The high availability mode keeps the instance serving when a host fails. The mode combines PostgreSQL streaming replication, virtual IP addresses managed by keepalived, Redis replication with Sentinel and a Gitaly cluster managed by Praefect. Every layer is disabled by default and is enabled independently in the configuration file of the container.
A cluster node is a container on its own host. The container runs the whole service tree of the package — nginx, Puma, Sidekiq, PostgreSQL, Redis, keepalived and Sentinel — and uses the network of the host directly, so the virtual IP addresses are managed on the host interface and the services listen on the host ports. The mode is enabled and operated on the pages of the Omnibus Docker installation type.
Topology
The reference cluster is three hosts with three containers in one L2 network segment:
| Node | Runs in the container |
|---|---|
| 1 | Application, Redis, Sentinel, PostgreSQL primary server, Gitaly and Praefect |
| 2 | Application, Redis, Sentinel, PostgreSQL standby server, Gitaly and Praefect |
| 3 | Application, Redis, Sentinel, PostgreSQL standby server, Gitaly and Praefect |
PostgreSQL runs on every node: one primary server that accepts writes and two standby servers that stream the write-ahead log (WAL). Sentinel needs at least three nodes with the quorum of 2 — in the reference cluster every node runs it. The cluster subnet example used across the high availability pages is 10.10.0.0/24: host addresses 10.10.0.1, 10.10.0.2, 10.10.0.3, the frontend virtual IP address 10.10.0.10 and the database virtual IP address 10.10.0.20.
On every node, gitlab_rails['db_host'] points at the database virtual IP address: the address moves between the nodes, so a failover needs no application configuration changes. The address of the instance (external_url) resolves to the frontend virtual IP address.
PostgreSQL layer
The standby server is a copy of the primary server that continuously replays the write-ahead log. Replication is asynchronous: the primary server confirms a transaction before the standby server has received it, so the tail of the WAL can be lost when the primary server dies. The failover commands make this tail explicit and require an administrator decision.
Failover is manual: promotion happens only through gitlab-ctl pg-failover promote and never as a side effect of gitlab-ctl reconfigure. On a standby node gitlab-ctl reconfigure renders the replication connection into postgresql.conf, creates the standby.signal marker once and never removes it. A physical replication slot on the primary server keeps the WAL for the standby server while it is away.
On a node with a high availability role, gitlab-ctl reconfigure raises the PostgreSQL settings to the values replication requires: wal_level = replica, max_wal_senders at least 3 and at least the number of the other database nodes, max_replication_slots at least the number of the other database nodes, hot_standby = on, wal_log_hints = on, and wal_keep_size not less than max_wal_size. The last two keep the node resynchronizable with pg_rewind after a failover instead of a full re-clone.
Virtual IP addresses
keepalived runs in every container and speaks VRRP (Virtual Router Redundancy Protocol) in unicast mode with the other hosts. It manages two virtual IP addresses. The address moves to a healthy node or disappears — clients always connect to the address.
The frontend virtual IP address is the entry point for users: the web interface and Git over SSH. A node holds it while its local web chain answers: an HTTP probe of /-/health passes through nginx, Workhorse and Rails, and a TCP probe checks the SSH port. After about 10 seconds of sustained failure the address moves to another node.
The database virtual IP address serves PostgreSQL clients. Only a node whose local PostgreSQL answers as the writable primary server holds it: every database node configures the same priority, and the check decides. A standby server, a stopped database or a fenced node releases the address. When no node qualifies, the address disappears entirely: client connections fail, and a stale primary server stays unreachable through the address. Releasing this address is an outage for the PostgreSQL clients, so the check waits for about 20 seconds of sustained failure.
A global gitlab-ctl start, stop or restart skips the keepalived service: the virtual IP addresses must not move during a routine restart. Operate the service explicitly with docker exec code gitlab-ctl restart keepalived.
Redis Sentinel
Redis replication with Sentinel provides an automatic failover of the cache and queue server. Sentinel runs on at least three nodes with the quorum of 2, monitors the Redis master server and, when it stops answering, promotes a replica and reconfigures the rest. The application nodes discover the current master server through the Sentinel list in gitlab_rails['redis_sentinels'], so no application configuration changes during a Redis failover.
The old master server rejoins the cluster as a replica when it returns. The Redis topology in /srv/code/config/gitlab.rb is static: after an actual switch the roles in it are aligned by hand, before the next run of gitlab-ctl reconfigure — the steps are on the Operations page. Only the default Redis instance is covered.
Gitaly and Praefect
The repository storage of the cluster is a Gitaly cluster under Praefect. Gitaly runs on every node and keeps its own copy of the repositories: with the replication factor of 3, Praefect stores three copies of every repository. Praefect also runs on every node. The Rails and gitlab-shell of a node talk to the local Praefect, and Praefect routes the requests to the healthy Gitaly nodes — a separate virtual IP address for Praefect is not needed.
Praefect keeps the cluster metadata in the praefect_production database of the shared PostgreSQL cluster, reached through the database virtual IP address. PostgreSQL failovers do not disturb Praefect: it reconnects on its own once the address settles, and repository writes pause for the duration of the switch.
When a Gitaly node fails, Praefect serves the requests from the remaining copies. When the node returns, the Praefect reconciler backfills the missing repositories on its own.
Split-brain protection
Split-brain (two nodes acting as writable primary servers at the same time) is prevented by several independent layers:
gitlab-ctl pg-failover promoterefuses to run while another node of the cluster verifiably answers as a writable primary server. The check goes over the SQL protocol with the dedicatedpostgresql['ha_check_user']credentials, without SSH between nodes.- The start guard of the PostgreSQL service refuses to start the database in the writable role while a peer node verifiably runs a writable primary server, including container restarts and host reboots. A peer that cannot be reached is treated as dead, so a cold boot of the whole cluster is not blocked.
- Fencing isolates the old primary server:
gitlab-ctl pg-failover fencestops PostgreSQL and creates thefenced.markerfile, and while the file exists the service refuses to start the database — the marker and the disabled autostart survive a restart of the container and the host. - The database virtual IP address is held only by the node whose local database answers as the writable primary server, so clients cannot reach a stale primary server through it.
Failover scenario
The steps of a failover are the same for a planned switchover and for a failure. What differs is how the administrator knows that the standby server has replayed the whole write-ahead log of the primary server: in a planned switchover the fencing command guarantees it, after a failure the administrator checks the log position or accepts the data loss:
- The old primary server is fenced:
docker exec code gitlab-ctl pg-failover fencestops PostgreSQL and prints the position in the WAL (LSN) up to which the standby server must replay. In a planned switchover,--switchoverfirst flushes the WAL. - The database virtual IP address leaves the fenced node after its check starts failing.
- The standby server is promoted:
docker exec code gitlab-ctl pg-failover promotewaits until the WAL is replayed to the printed position and refuses to promote while a live peer primary server exists. Without a printed position the command requires the explicit--allow-data-loss. - The roles are flipped in the configuration file on every node and applied with
docker exec code gitlab-ctl reconfigure. - The fenced node rejoins as a standby server:
docker exec code gitlab-ctl pg-failover rejoinresynchronizes it withpg_rewindor re-clones it withpg_basebackup.
After a failure, only the transactions that the primary server confirmed but did not pass to the standby server can be lost. The docker exec code gitlab-ctl pg-failover promote --allow-data-loss command prints the last received and replayed log positions and asks for a confirmation.
The exact commands are on the Operations page.
Limitations
- PostgreSQL failover is performed by the administrator: after a primary server failure the database clients get connection errors until the commands from the Operations page are run.
- A PostgreSQL major upgrade of a running cluster goes through a switchover:
gitlab-ctl upgradeandgitlab-ctl pg-upgradeabort on a standby node. - Only the default Redis instance is covered by Sentinel.
- The files of the instance — uploads, CI artifacts, LFS objects, packages, Terraform states and the rest — stay on the disk of the node that wrote them: the mode does not replicate them between nodes, and they are lost together with the node when it is lost. Move them to object storage — the Object storage page.
- The repositories of an instance moved from a single-node installation keep the single-Gitaly layout (
@hashed); moving them to the cluster layout (@cluster/repositories) is a migration of its own. - With
--allow-data-loss, a network partition can leave two writable primary servers for a while: the old primary server that lost contact keeps its data and can still accept writes from clients that reach it. Keep port 5432 open inside the cluster subnet only, so clients always connect through the database virtual IP address. - The mode requires the container to run in the host network with the
NET_ADMINandNET_RAWcapabilities (see Requirements and topology): the virtual IP addresses live on the interface of the host, and a container with published ports cannot take part in VRRP.