This template repo was built to facilitate a data migration from a standalone Postgres instance to a Postgres Cluster running in Railway.
Optionally, by setting an environment variable, it can also set up replication between the standalone instance and the Cluster. More info on this below.
Deploy this service into your Railway project and configure the required variables:
PRIMARY_URL
- URL of the primary node in your cluster.
If you've just deployed the Postgres cluster from the template in Railway, the primary node should bepg-0
.STANDALONE_URL
- URL of the standalone Postgres instance.
It is highly recommended to deploy these services into the same Railway project, to take advantage of the private network.
When setting the URLs, you can either hardcode the values, or use reference variables. An example of both is shown in the image below.
Once deployed, the script will connect to the standalone instance and dump each database within. It will then restore each of them to the Primary node in the cluster to be replicated among the standby nodes.
This script can also enable replication between the standalone Postgres instance and cluster, to maintain a data sync after the initial migration.
This is useful for those who wish to test the cluster prior to moving traffic from their application.
To set up replication, simply update the value of the pre-configured environment variable:
ENABLE_REPLICATION=true
RAILWAY_API_TOKEN=your-api-token
(docs for reference).
WARNING: This will restart your standalone Postgres instance in order to apply the wal_level configuration required to replicate data.