---
title: "Deploy Postgres HA"
description: "High-availability PostgreSQL cluster with Patroni, etcd, and HAProxy"
url: https://railway.com/deploy/postgres-ha
---

# Deploy Postgres HA

High-availability PostgreSQL cluster with Patroni, etcd, and HAProxy

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

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/postgres-ha/manifest.json

## Template content

### etcd-1 https://upload.wikimedia.org/wikipedia/labs/5/53/Etcd_logo.png

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/etcd:3

### etcd-2 https://upload.wikimedia.org/wikipedia/labs/5/53/Etcd_logo.png

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/etcd:3

### etcd-3 https://upload.wikimedia.org/wikipedia/labs/5/53/Etcd_logo.png

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/etcd:3

### Postgres HA https://cms.railway.com/media/haproxy-icon.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/haproxy:3

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

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/postgres-patroni:18

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

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/postgres-patroni:18

### Postgres-3 https://devicons.railway.app/postgres

- **Image:** ghcr.io/railwayapp-templates/postgres-ha/postgres-patroni:18

## Documentation

# Postgres HA

A highly available PostgreSQL cluster using:
- **Patroni** for automatic failover and cluster management
- **etcd** for distributed consensus
- **HAProxy** for connection routing and load balancing

## Architecture

- **Postgres-1 (Primary)**: The primary database node
- **Postgres-2+ (Replicas)**: Streaming replicas for read scaling and failover
- **etcd-1/2/3 (Internal)**: Distributed key-value store for cluster state
- **Postgres HA (Edge)**: HAProxy load balancer for client connections

## Connecting

Use the `DATABASE_URL` or `DATABASE_PUBLIC_URL` from the "Postgres HA" (HAProxy) service.
Do not connect directly to individual Postgres nodes.

## Scaling

- **Postgres replicas**: Scale from 2-5 nodes using the cluster overview
- **etcd nodes**: Scale from 3-7 nodes (must be odd for quorum)


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