---
title: "Deploy PostgreSQL Migration Service"
description: "Migrate data from a standalone Postgres instance to a cluster"
category: "Storage"
url: https://railway.com/deploy/VgqHWg
---

# Deploy PostgreSQL Migration Service

Migrate data from a standalone Postgres instance to a cluster

**[Deploy PostgreSQL Migration Service on Railway](https://railway.com/template/VgqHWg)**

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

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

## Template content

### pg-migrate-ha

- **Source:** railwayapp-templates/pg-migrate-ha

## Documentation

This template deploys a script which migrates your Postgres databases from a standalone instance to a Highly Available Cluster.

Optionally, it can also enable replication between the Standalone and the Cluster, to facilitate an incremental migration.

## How to use

Deploy this template into the Railway project that contains the standalone Postgres instance and the Postgres cluster. 
 If needed, you can deploy a cluster from the [HA Postgres template](https://railway.app/template/ha-postgres).

Set the required variables:
- `PRIMARY_URL` - URL of the *primary node* in your cluster.  If deployed from the HA Postgres template, it is likely `pg-0` but you can check by querying `show pool_nodes;` using psql against the cluster (via PgPool).
- `STANDALONE_URL` - URL of the standalone Postgres instance.

You can either hardcode the values, or use [reference variables](https://docs.railway.app/guides/variables#reference-variables).

### Enable replication

The script can optionally enable replication between the Standalone and the Cluster, to facilitate an incremental cutover to the Cluster.  To leverage this function, you should set the required environment variables for enabling replication:

- `ENABLE_REPLICATION` - Set to "true" (lowercase)
- `RAILWAY_API_TOKEN` - Your [Railway API token](https://docs.railway.app/reference/public-api#authentication).  Required to restart the Standalone instance to apply the required configuration.

## Similar templates

- [RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set](https://railway.com/deploy/rustfs-or-just-updated-s3-object-store-p) — S3-compatible object store, keys and public URL preset, volume kept
- [TimescaleDB](https://railway.com/deploy/timescaledb-railway-template) — A PostgreSQL-based time-series database for analytics on Railway.
- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.

Open this page in a browser: https://railway.com/deploy/VgqHWg
