PostgreSQL Copy Tool - Copy databases like cp copies files.
Note: Currently macOS only.
npx pgcp <source_url> <destination_url># Run directly without installing
npx pgcp <source> <destination>
# Or install globally
npm install -g pgcp# Default mode: copy between any postgres databases
pgcp <source> <destination>
# Supabase mode: copy to local Supabase (manages local instance lifecycle)
pgcp --supabase <source> <destination><source>- Source database URL orenv:VARNAME<destination>- Destination database URL orenv:VARNAME
--supabase- Use Supabase mode (destination is local Supabase, managed automatically)--schema-only, -s- Copy schema only, skip data--keep-dumps, -k- Keep dump files after completion--help, -h- Show help message
# Copy from remote postgres to local postgres
npx pgcp postgres://user:pass@remote:5432/prod postgresql://localhost:5433/local
# Use env variables from .env.local
npx pgcp env:PROD_DATABASE_URL env:LOCAL_DATABASE_URL
# Copy schema only (no data)
npx pgcp --schema-only env:PROD_DB env:LOCAL_DB
# Supabase mode: copy Supabase DB to local Supabase (automatic setup)
npx pgcp --supabase env:SUPABASE_DATABASE_URL postgresql://postgres:postgres@localhost:54322/postgresAutomatically loads .env and .env.local from the current directory. Use the env:VARNAME syntax to reference variables from these files.
- pg_dump (
brew install libpq && brew link --force libpq) - psql
- Node.js >= 18
- Docker (running)
- Supabase CLI (
brew install supabase/tap/supabase) - psql
- Node.js >= 18
- Checks prerequisites (pg_dump, psql)
- Verifies destination database is accessible
- Dumps source database using pg_dump
- Restores to destination using psql
- Cleans up dump files (unless
--keep-dumps)
- Checks prerequisites (Docker, Supabase CLI, psql)
- Stops existing local Supabase
- Starts fresh local Supabase
- Waits for Postgres readiness
- Dumps from source: roles -> schema -> data (optional)
- Restores to local: roles -> grant roles -> schema -> data (triggers disabled)
- Cleans up dump files (unless
--keep-dumps)
Requires bun for development and publishing.
bun install
bun run buildMIT