Migrate from Google AlloyDB to Xata

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

Prerequisites

  • Google AlloyDB PostgreSQL cluster
  • Access to Google Cloud Console
  • Xata account and project setup
  • Network access to your AlloyDB cluster

Create Snapshot User

Connect to your AlloyDB cluster and create a dedicated user for migration:

-- Create snapshot user
CREATE USER xata_snapshot WITH LOGIN PASSWORD 'your_secure_password';

-- Grant necessary privileges
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xata_snapshot;
GRANT USAGE ON SCHEMA public TO xata_snapshot;

-- Grant privileges on future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO xata_snapshot;

Network Configuration

Option 1: Public IP (Less Secure)

If your AlloyDB cluster has a public IP:

  1. Authorize Your IP:
    • Go to your AlloyDB cluster → "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 AlloyDB cluster → "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 AlloyDB cluster

Option 3: AlloyDB Auth Proxy

Use AlloyDB Auth Proxy for secure connections:

# Install AlloyDB Auth Proxy
curl -o alloydb-auth-proxy https://storage.googleapis.com/alloydb-auth-proxy/v1.0.0/alloydb-auth-proxy.linux.amd64
chmod +x alloydb-auth-proxy

# Start the proxy
./alloydb-auth-proxy --instances=your-project:your-region:your-cluster

Get Connection String

Connection String Format

postgresql://xata_snapshot:your_password@your-alloydb-ip:5432/your_database

Find Your Cluster Details

  1. Go to AlloyDB Console → Clusters
  2. Click on your cluster
  3. Note the Public IP address (if using public IP)
  4. Note the Private IP address (if using private IP)

SSL Configuration

AlloyDB requires SSL by default. Include SSL parameters in your connection string:

postgresql://xata_snapshot:your_password@your-alloydb-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://xata_snapshot:your_password@your-alloydb-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:

    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

Troubleshooting

Common Issues

  1. Connection Refused:

    • Check authorized networks
    • Verify the IP address is correct
    • Ensure the cluster is running
  2. SSL Connection Required:

    • Add ?sslmode=require to your connection string
    • Or use AlloyDB Auth Proxy for secure connections
  3. Permission Denied:

    • Verify the snapshot user has correct privileges
    • Check that the user has sufficient permissions
  4. Cluster Configuration Issues:

    • Wait for the cluster restart to complete
    • Verify configuration is set correctly in the console

Using AlloyDB Auth Proxy

If you're having connection issues, try using AlloyDB Auth Proxy:

# Start proxy
./alloydb-auth-proxy --instances=your-project:your-region:your-cluster

# Use localhost in connection string
export XATA_CLI_SOURCE_POSTGRES_URL="postgresql://xata_snapshot:your_password@localhost:5432/your_database"

# Run migration
xata clone start --source-url $XATA_CLI_SOURCE_POSTGRES_URL

AlloyDB-Specific Features

AlloyDB Omni

If you're using AlloyDB Omni (self-hosted):

  • Same PostgreSQL compatibility as cloud AlloyDB
  • Follow self-hosted PostgreSQL migration guide
  • Use local connection instead of cloud endpoints

AlloyDB for PostgreSQL

For standard AlloyDB for PostgreSQL:

  • Full PostgreSQL compatibility
  • Enhanced performance features
  • Same migration process as other PostgreSQL databases

Security Best Practices

  1. Use Private IP when possible
  2. Remove public IP access after migration
  3. Use strong passwords for snapshot users
  4. Limit authorized networks to specific IPs
  5. Enable Cloud Audit Logs to monitor access

Next Steps