Overview
This migration method involves:1
Setting up logical replication from your source database
2
Creating an initial data snapshot
3
Continuously streaming WAL changes to keep databases synchronized
4
Performing a quick cutover when ready
WarningThis method requires administrative access to your source PostgreSQL database to configure replication settings.
Prerequisites
Before starting the migration:- PostgreSQL 10+ on the source database (logical replication support)
- Administrative access to source database configuration
- Network connectivity between source and PlanetScale for Postgres
- Connection details for your PlanetScale for Postgres database from the console
- Ensure the disk on your PlanetScale database has at least 150% of the capacity of your source database. If you are migrating to a PlanetScale database backed by network-attached storage, you can resize your disk manually by setting the “Minimum disk size.” If you are using Metal, you will need to select a size when first creating your database. For example, if your source database is 330GB, you should have at least 500GB of storage available on PlanetScale.
- Understanding of your application’s write patterns for cutover planning
Step 1: Configure Source Database
Enable logical replication on source database:
Edit your PostgreSQL configuration (postgresql.conf
):
Configure authentication (pg_hba.conf
):
Add an entry to allow replication connections:
Restart PostgreSQL service:
Step 2: Create Replication User
Connect to your source database and create a replication user:Step 3: Create Publication on Source
Create a publication for the tables you want to replicate:Step 4: Get PlanetScale Connection Details
From your PlanetScale console:1
Navigate to your PlanetScale for Postgres database
2
Go to the “Connect” section
3
Copy the connection details including:
- Host
- Port
- Database name
- Username
- Password
Step 5: Create Initial Schema on PlanetScale
Export and import the schema structure:Step 6: Create Initial Data Copy
Create an initial data snapshot:Step 7: Set Up Logical Replication
Connect to PlanetScale for Postgres and create subscription:Step 8: Monitor Replication
Check replication lag:
Monitor for conflicts:
Step 9: Prepare for Cutover
Verify data consistency:
Check replication lag:
Ensure replication lag is minimal (ideally under 1 second) before cutover.Step 10: Perform Cutover
When ready to switch to PlanetScale for Postgres:1
Stop application writes to the source database
2
Wait for replication to catch up (monitor lag)
3
Update application connection strings to point to PlanetScale
4
Start application with new connection
5
Monitor for any issues
Verify cutover success:
Step 11: Cleanup (After Successful Cutover)
Drop subscription on PlanetScale:
Drop publication on source:
Troubleshooting
Common Issues:
Replication slot conflicts:- Verify replication user has correct permissions
- Check pg_hba.conf configuration
- Ensure network connectivity
- Monitor for long-running transactions on source
- Consider breaking large operations into smaller batches
Performance Considerations
- Network bandwidth: Ensure sufficient bandwidth for initial sync and ongoing replication
- Disk I/O: Monitor disk usage on both source and target during replication
- Replication lag: Keep lag minimal by optimizing source database performance
- Conflict resolution: Understand how PostgreSQL handles replication conflicts
Schema Considerations
Before migration, review:Next Steps
After successful migration:1
Monitor replication performance and lag
2
Test application functionality thoroughly
3
Set up monitoring and alerting for the new database
4
Plan for ongoing maintenance and optimization