Migrate from GCP Cloud SQL to Xata

Learn how to migrate your GCP Cloud SQL PostgreSQL database to Xata using xata clone. Step-by-step instructions for configuring the migration.

Prerequisites

  • GCP Cloud SQL PostgreSQL instance
  • Access to Google Cloud Console
  • Xata account and project setup
  • Network access to your Cloud SQL instance

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 IP (Less Secure)

If your Cloud SQL instance has a public IP:

  1. Authorize Your IP:
    • Go to your Cloud SQL instance → "Connections" → "Networking"
    • Add your IP address to "Authorized networks"
    • Or temporarily add 0.0.0.0/0 for migration (remove after)

For better security, use private IP:

  1. Enable Private IP:

    • Go to your Cloud SQL instance → "Connections" → "Networking"
    • Enable "Private IP"
    • Configure VPC peering if needed
  2. Run Migration from GCP:

    • Use Cloud Run, Compute Engine, or Cloud Functions
    • Ensure the service is in the same VPC as your Cloud SQL

Option 3: Cloud SQL Proxy

Use Cloud SQL Proxy for secure connections:

# Install Cloud SQL Proxy
curl -o cloud-sql-proxy https://dl.google.com/cloudsql/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy

# Start the proxy
./cloud-sql-proxy --instances=your-project:your-region:your-instance

Get Connection String

postgresql://your_username:your_password@your-cloudsql-ip:5432/your_database?sslmode=require

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-cloudsql-ip:5432/your_database?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:

  1. Connect to Xata Branch:

    psql `xata branch url`
  2. Check Data Integrity:

    -- Compare row counts
    SELECT COUNT(*) FROM your_table;
    
    -- Check sample data
    SELECT * FROM your_table LIMIT 10;
  3. Test Relationships: Verify foreign key relationships work correctly

Next Steps