Migrate from DigitalOcean Managed Databases to Xata
Learn how to migrate your DigitalOcean Managed Database for PostgreSQL to Xata using xata clone. Step-by-step instructions for enabling logical replication and configuring the migration.
Prerequisites
- DigitalOcean Managed Database for PostgreSQL
- Access to DigitalOcean Console
- Xata account and project setup
- Network access to your DigitalOcean database
Install and Configure the Xata CLI
Install the Xata CLI:
curl -fsSL https://xata.io/install.sh | bash
Authenticate with your Xata account:
xata auth login
Network Configuration
Option 1: Public Access (Default)
DigitalOcean Managed Databases are typically accessible from the internet:
- No additional configuration needed for public access
- SSL is required by default
- Connection limits may apply based on your plan
Option 2: Private Network (Premium Plans)
If you're on a Premium plan with private network:
-
Enable Private Network:
- Go to your database cluster → "Settings" → "Networking"
- Enable "Private Network"
- Configure VPC peering if needed
-
Run Migration from DigitalOcean:
- Use Droplets in the same private network
- Use App Platform or Functions in the same VPC
Get Connection String
Find Your Connection Details
- Go to DigitalOcean Console → Databases
- Click on your PostgreSQL cluster
- Go to "Settings" → "Connection Details"
- Copy the connection string
Connection String Format
DigitalOcean connection strings typically look like this:
postgresql://your_username:your_password@your-db-host:5432/defaultdb?sslmode=require
Replicate Database Roles
Before migrating your data, you'll need to replicate the database roles from your source database to your Xata branch.
Extract Roles from Source Database
Connect to your source database and extract the role definitions:
-- Extract role definitions (run this on your source database)
SELECT
'CREATE ROLE ' || rolname || ' WITH ' ||
CASE WHEN rolcanlogin THEN 'LOGIN ' ELSE 'NOLOGIN ' END ||
CASE WHEN rolsuper THEN 'SUPERUSER ' ELSE 'NOSUPERUSER ' END ||
CASE WHEN rolinherit THEN 'INHERIT ' ELSE 'NOINHERIT ' END ||
CASE WHEN rolcreaterole THEN 'CREATEROLE ' ELSE 'NOCREATEROLE ' END ||
CASE WHEN rolcreatedb THEN 'CREATEDB ' ELSE 'NOCREATEDB ' END ||
CASE WHEN rolreplication THEN 'REPLICATION ' ELSE 'NOREPLICATION ' END ||
CASE WHEN rolbypassrls THEN 'BYPASSRLS ' ELSE 'NOBYPASSRLS ' END ||
'CONNECTION LIMIT ' || COALESCE(rolconnlimit, -1) || ';' as create_role_statement
FROM pg_roles
WHERE rolname NOT LIKE 'pg_%'
ORDER BY rolname;
Apply Roles to Xata Branch
-
Connect to your Xata branch:
psql `xata branch url`
-
Execute the role creation statements from the previous step
Initialize Xata Project
Set up your Xata project configuration:
xata init
Configure the Migration
Set up your clone configuration with optional anonymization:
# Set your source URL
export XATA_CLI_SOURCE_POSTGRES_URL="postgresql://your_username:your_password@your-db-host:5432/defaultdb?sslmode=require"
# Configure anonymization rules
xata clone config --source-url $XATA_CLI_SOURCE_POSTGRES_URL --mode prompt
Start the Migration
Begin the data transfer:
# Start the migration
xata clone start --source-url $XATA_CLI_SOURCE_POSTGRES_URL
Monitor Progress
Check the migration status:
xata clone status
Verification
After migration, verify your data:
-
Connect to Xata Branch:
psql `xata branch url`
-
Check Data Integrity:
-- Compare row counts SELECT COUNT(*) FROM your_table; -- Check sample data SELECT * FROM your_table LIMIT 10;
-
Test Relationships: Verify foreign key relationships work correctly
Next Steps
- Explore Xata branching for development workflows
- Learn about schema changes with zero downtime
- Set up continuous sync for ongoing replication
- Consider deployment options for your Xata instance