Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dbdock.xyz/llms.txt

Use this file to discover all available pages before exploring further.

npx dbdock copydb <source-url> <target-url> [options]
copydb is the “I just need to move this database” command. No config file. No intermediate backup file. Just paste two URLs and go.

Quick example

npx dbdock copydb \
  "postgresql://user:pass@prod.example.com:5432/myapp" \
  "postgresql://user:pass@staging.example.com:5432/myapp"

What it does

  1. Tests both connections
  2. Shows source database size and table count
  3. Warns if the target has existing data
  4. Asks for confirmation
  5. Streams pg_dump directly into pg_restore — no temp files, no waiting

Options

OptionDescription
--schema-onlyCopy tables, indexes, constraints — no data
--data-onlyCopy data only (schema must already exist on target)
--verboseShow detailed pg_dump/pg_restore output
--driverUse direct PostgreSQL driver instead of pg_dump. Required for serverless/modified Postgres (Neon, Supabase pooler, PlanetScale Postgres, etc.)

Common use cases

Refresh staging from production

npx dbdock copydb "$PROD_URL" "$STAGING_URL"

Promote staging to production

npx dbdock copydb "$STAGING_URL" "$PROD_URL"

Pull production down to local for debugging

npx dbdock copydb "$PROD_URL" "postgresql://postgres:pass@localhost:5432/myapp"

Align schema across environments

npx dbdock copydb --schema-only "$PROD_URL" "$STAGING_URL"

The --driver flag

Some serverless Postgres services (Neon, Supabase pooler, and others that use modified Postgres) reject pg_dump because it requires specific superuser operations or exact version matches. If you hit errors like:
pg_dump: error: server version: 15.3; pg_dump version: 14.9
or
pg_dump: error: could not connect to server
…use the --driver flag to use DBdock’s direct Postgres client instead:
npx dbdock copydb --driver "$NEON_URL" "$LOCAL_URL"
The driver mode does not support all pg_dump features (e.g., function/procedure bodies for non-PL/pgSQL languages). Use pg_dump mode when possible.

Safety

copydb refuses to proceed silently when the target database has data. You’ll see a confirmation prompt listing target size and table count before anything writes. If you’re scripting this in CI, wrap it with an explicit empty target:
psql "$TARGET_URL" -c "DROP DATABASE IF EXISTS myapp; CREATE DATABASE myapp;"
npx dbdock copydb "$SOURCE_URL" "$TARGET_URL"

See also

Staging refresh guide

End-to-end workflow for syncing environments.

Cross-database migration

Moving between MongoDB and Postgres.