Overview
This migration method involves:- Creating a full backup of your source database using
pg_dump
- Transferring the dump file to your local environment or staging area
- Restoring the database to PlanetScale for Postgres using
pg_restore
orpsql
Prerequisites
Before starting the migration:- Ensure you have PostgreSQL client tools installed (
pg_dump
,pg_restore
,psql
) - Have read access to your source PostgreSQL database
- Have 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.
- Verify sufficient storage space for the dump file
- Plan for application downtime during the migration
Step 1: Create Database Dump
For a complete database dump:
For a custom format dump (recommended for large databases):
Command options explained:
--verbose
: Provides detailed output during the dump process--no-owner
: Excludes ownership information from the dump--no-privileges
: Excludes privilege information from the dump-Fc
: Creates a custom format dump (binary, compressed)-f
: Specifies the output file name
Step 2: 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 3: Restore to PlanetScale for Postgres
For SQL format dumps:
For custom format dumps:
For parallel restoration (faster for large databases):
Step 4: Verify Migration
After the restore completes, verify your migration:Check table counts:
Verify data integrity:
Check for errors in logs:
Review the output from the pg_restore command for any errors or warnings.Troubleshooting
Common Issues:
Permission errors:- Ensure your PlanetScale user has appropriate permissions
- Check that connection details are correct
- Some PostgreSQL extensions may not be available in PlanetScale for Postgres
- Review the extension compatibility guide
- If using large objects (BLOBs), add
--blobs
flag to pg_dump
- For large databases, consider breaking the dump into smaller chunks
- Use custom format with parallel restoration
Performance Tips:
- Use custom format: Binary format with compression is more efficient
- Parallel jobs: Use
--jobs
parameter for faster restoration - Network considerations: Ensure stable network connection for large transfers
- Disk space: Monitor available disk space during dump creation
Schema Considerations
Before migration, review:Next Steps
After successful migration:1
Update your application connection strings to point to PlanetScale for Postgres
2
Test your application thoroughly in a staging environment
3
Plan your production cutover
4
Monitor performance and optimize as needed