---
title: "Deploy 🚀 TimescaleDB HA (Primary + Replica)"
description: "🚀 TimescaleDB HA: Primary + Replica with Pgpool Load Balancer"
category: "Storage"
url: https://railway.com/deploy/timescaledb-replica-postgresql
---

# Deploy 🚀 TimescaleDB HA (Primary + Replica)

🚀 TimescaleDB HA: Primary + Replica with Pgpool Load Balancer

**[Deploy 🚀 TimescaleDB HA (Primary + Replica) on Railway](https://railway.com/template/timescaledb-replica-postgresql)**

- **Creator:** iCue
- **Category:** Storage
- **Total deploys:** 4

## Template content

### timescale-proxy https://devicons.railway.app/i/timescale-light.svg

- **Source:** icueth/railsway-timescaledb-replica

### timescale-primary https://devicons.railway.app/i/timescale-light.svg

- **Source:** icueth/railsway-timescaledb-replica

### timescale-replica https://devicons.railway.app/i/timescale-light.svg

- **Source:** icueth/railsway-timescaledb-replica

## Documentation

# Deploy and Host TimescaleDB Replica (PostgreSQL) on Railway

**TimescaleDB Replica** is an enterprise-grade time-series database solution built on PostgreSQL 17. It combines the power of SQL with high-availability (HA) architecture, featuring a primary-replica pair and a centralized proxy for intelligent connection management, ensuring your time-series workloads are always fast, stable, and resilient.

## About Hosting TimescaleDB Replica (PostgreSQL)

Deploying this TimescaleDB cluster on Railway provides an out-of-the-box production environment without the operational overhead. This template utilizes a robust 3-node architecture: a **Primary** node for write operations, a **Replica** node for real-time data synchronization and heavy reads, and a **Pgpool-II Proxy** that acts as the intelligent gateway. The system includes an automated setup that handles replication slots, credential synchronization, and health monitoring. It also features a zero-config "Auto-Tuning" mechanism that optimizes your database parameters based on your assigned Railway resources, guaranteeing peak performance from the moment of deployment.

## 📊 Performance Benchmarks

### Load Test Results (Internal Network)

| Test Scenario                               | Throughput    | Avg Latency | Success Rate |
| ------------------------------------------- | ------------- | ----------- | ------------ |
| Light Load - Simple Reads                   | 1,523 ops/sec | 656µs       | 100%         |
| Light Load - Simple Writes                  | 892 ops/sec   | 1.12ms      | 100%         |
| Medium Load - Mixed R/W (70/30)             | 1,245 ops/sec | 803µs       | 99.9%        |
| Medium Load - Batch Inserts                 | 756 ops/sec   | 1.32ms      | 100%         |
| Heavy Load - Concurrent Reads (20 workers)  | 3,456 ops/sec | 289µs       | 100%         |
| Heavy Load - Concurrent Writes (20 workers) | 1,892 ops/sec | 528µs       | 99.8%        |
| Stress Test - Max Throughput (50 workers)   | 2,345 ops/sec | 426µs       | 99.8%        |
| TimescaleDB - Time Series Insert            | 1,678 ops/sec | 596µs       | 100%         |
| TimescaleDB - Time Range Query              | 2,134 ops/sec | 468µs       | 100%         |
| Complex - Aggregation Queries               | 456 ops/sec   | 2.19ms      | 100%         |

### Replication Lag Test (Primary → Replica)

| Metric                  | Value                                        |
| ----------------------- | -------------------------------------------- |
| Average Replication Lag | &lt; 10ms                                       |
| Minimum Replication Lag | ~2ms                                         |
| Maximum Replication Lag | ~15ms                                        |
| P50 (Median) Lag        | ~5ms                                         |
| P95 Lag                 | ~12ms                                        |
| P99 Lag                 | ~14ms                                        |
| **Rating**              | ⭐ **EXCELLENT** - Replication is very fast! |

&gt; **Note**: Benchmarks conducted on Railway internal network. External network performance may vary due to network latency.

## Common Use Cases

- **IoT &amp; Industrial Telemetry**: Ingest and analyze millions of data points per second from global sensor networks.
- **Financial Market Data**: Store and query high-frequency trading data, crypto prices, or transaction history with millisecond precision.
- **Application Monitoring**: Efficiently manage logs, metrics, and user behavior events with 10-100x better performance than standard SQL.

## Dependencies for TimescaleDB Replica (PostgreSQL) Hosting

- **PostgreSQL 17 Engine**: The bedrock of the cluster, providing modern SQL features and security.
- **TimescaleDB 2.24.0 Extension**: Optimized hypertables for time-series data management.
- **Pgpool-II**: High-performance proxy for connection pooling and Read/Write splitting.

### Deployment Dependencies

- [Railway App](https://railway.app)
- [TimescaleDB Official Documentation](https://docs.timescale.com/)

### Implementation Details

To get started, you only need to configure the `POSTGRES_PASSWORD` environment variable. Once deployed, the cluster handles all internal communication automatically. **Always connect through the Proxy node** to utilize the high-availability and load-balancing features.

#### 🛰️ Internal / Private Connection (Recommended)

Use this for applications running within the same Railway project.

- **Host**: `timescale-proxy.railway.internal`
- **Port**: `5432`
- **User**: `postgres`
- **Password**: Your `${POSTGRES_PASSWORD}`

#### 🌍 External / Public Connection

For local development or database management tools (DBeaver/TablePlus).

1. Navigate to the **timescale-proxy** service in Railway.
2. Go to **Settings** &gt; **Public Networking** &gt; **TCP Proxy**.
3. Use the generated Public Domain and Port (e.g., `monorail.proxy.rlwy.net:12345`).

## Architecture

```
┌─────────────────────────────────────────────────────────────────┐
│                        Railway Project                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────────┐         ┌─────────────────┐               │
│  │  timescale-     │         │  timescale-     │               │
│  │  primary        │ ──────► │  replica        │               │
│  │                 │ Streaming│                 │               │
│  │  (Read/Write)   │ Replication (Read-Only)   │               │
│  └────────┬────────┘         └────────┬────────┘               │
│           │                           │                         │
│           └───────────┬───────────────┘                         │
│                       │                                         │
│              ┌────────▼────────┐                               │
│              │  timescale-     │                               │
│              │  proxy          │◄──── Your Application         │
│              │  (Pgpool-II)    │                               │
│              │                 │                               │
│              │  • Connection   │                               │
│              │    Pooling      │                               │
│              │  • R/W Split    │                               │
│              │  • Load Balance │                               │
│              └─────────────────┘                               │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘
```

## Why Deploy TimescaleDB Replica (PostgreSQL) on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying TimescaleDB Replica (PostgreSQL) on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## 🧪 Load Test Tool (Included)

This template includes a built-in load testing tool (`loadtest-db/`) that you can deploy to benchmark your cluster:

```bash
# Environment Variables
DB_HOST=timescale-proxy.railway.internal
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=${POSTGRES_PASSWORD}

# For Replication Lag Test
REPLICA_HOST=timescale-replica.railway.internal
ENABLE_REPLICATION_TEST=true
```

Features:

- 10 different load test scenarios
- Replication lag measurement with P50/P95/P99 statistics
- Railway-friendly logging (auto-disable colors)

---
## Support This Project

If this template saves you time and money, consider supporting its development! ☕

[![Support Me](https://img.shields.io/badge/Support%20Me-Stripe-blue?style=for-the-badge&logo=stripe)](https://buy.stripe.com/14A28sbLa5mJ8SM5qY2VG01)


## 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
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/timescaledb-replica-postgresql
