---
title: "Deploy PostgreSQL HA with Repmgr"
description: "Instant Postgres cluster for high availability and redundancy"
category: "Storage"
url: https://railway.com/deploy/ha-postgres
---

# Deploy PostgreSQL HA with Repmgr

Instant Postgres cluster for high availability and redundancy

**[Deploy PostgreSQL HA with Repmgr on Railway](https://railway.com/template/ha-postgres)**

- **Creator:** Railway Templates
- **Category:** Storage
- **Total deploys:** 118

## Template content

### pgpool https://devicons.railway.app/postgres

- **Image:** railwayapp/pgpool:latest
- **Start command:** `/bin/sh -c "sleep 75 && /opt/bitnami/scripts/pgpool/entrypoint.sh /opt/bitnami/scripts/pgpool/run.sh"`

### pg-0 https://devicons.railway.app/postgres

- **Image:** railwayapp/postgresql-repmgr:16

### pg-1 https://devicons.railway.app/postgres

- **Image:** railwayapp/postgresql-repmgr:16

### pg-2 https://devicons.railway.app/postgres

- **Image:** railwayapp/postgresql-repmgr:16

## Documentation

Deploy a PostgreSQL HA Cluster with [replication manager by EDB](https://www.repmgr.org/), for a more highly available and redundant data layer.

## How it works

This template deploys 4 services -
- (3) PostgreSQL nodes
- (1) Pgpool-II service

The PostgreSQL nodes are automatically configured with [repmgr](https://www.repmgr.org/) and joined to a cluster.  Since Postgres doesn't include a native failover, repmgr is included.

[Pgpool-II](https://pgpool.net/mediawiki/index.php/Main_Page) is a PostgreSQL proxy which can also handle failovers when they occur in the cluster.


### Inter-node communication
All communication between nodes is done over the private network.

### Configuration Tuning
The PostgreSQL nodes and Pgpool-II are deployed from bitnami images.  As such, you can leverage the customizable environment variables available in both -
- [PostgreSQL-RepMgr](https://github.com/bitnami/containers/blob/main/bitnami/postgresql-repmgr/README.md#environment-variables)
- [Pgpool-II](https://github.com/bitnami/containers/blob/main/bitnami/pgpool/README.md#environment-variables)

## Connecting to the Cluster

Within the service variables for the Pgpool service, you will find connection strings named `DATABASE_URL` and `DATABASE_PUBLIC_URL`.  These can be used for connecting to the cluster via the private or public network.

*We strongly encourage you to use the private connection string defined in `DATABASE_URL` to avoid egress fees.*

## Deployment Regions

By default, each of the 3 Postgres nodes are deployed into US-West.  You can move them to your preferred region(s) once deployed into your project, from the service settings.

From a disaster preparedness standpoint, it is common practice to deploy the nodes into different regions.

## Service Source

**PostgreSQL nodes**- As of now, the PostgreSQL nodes deploy from a forked repository in the railwayapp-templates Github while we await a PR review by bitnami.  Once our PR has been merged and the image published via Bitnami, we will update the source

**Pgpool-II** - Pgpool deploys directly from the [bitnami/pgpool image](https://hub.docker.com/r/bitnami/pgpool) in Docker Hub.

## More Resources
- [PostgreSQL Documentation](https://www.postgresql.org/docs/16/index.html)
- [Replication Manager Documentation](https://www.repmgr.org/docs/5.3/index.html)
- [Pgpool-II Documentation](https://www.pgpool.net/docs/latest/en/html/)
- [bitnami/postgresql-repmgr in Docker Hub](https://hub.docker.com/r/bitnami/postgresql-repmgr)
- [bitnami/pgpool in Docker Hub](https://hub.docker.com/r/bitnami/pgpool)

## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [Postgres Backup to Cloudflare R2 (S3-Compatible)](https://railway.com/deploy/postgres-to-r2-backup) — Automated PostgreSQL backups to S3-compatible storage with encryption

Open this page in a browser: https://railway.com/deploy/ha-postgres
