You can connect to remote PostgreSQL databases (e.g., Neon, AWS RDS, etc.) using connection strings:
macOS/Windows:
psql "postgresql://username:password@host:port/database?sslmode=require"
Example (Neon database):
Export the connection string from the Neon console as an environment variable first. Never paste a real connection string, with its password, into these docs.
export ZOOLY_REMOTE_DB_URL="postgresql://<user>:<password>@<endpoint>-pooler.<region>.aws.neon.tech/neondb?sslmode=require&channel_binding=require"
psql "$ZOOLY_REMOTE_DB_URL"
Using connection parameters:
psql -h hostname -p port -U username -d database
To copy a remote database to your local PostgreSQL instance:
# macOS
createdb zooly2_local
# Windows
psql -U postgres -c "CREATE DATABASE zooly2_local;"
Using pg_dump and psql:
# Dump remote database and pipe to local database
pg_dump --no-owner "postgresql://remote_user:password@remote_host:port/remote_db?sslmode=require" | \
psql "postgresql://postgres:password@localhost:5432/zooly2_local?sslmode=disable"
Example with Neon:
pg_dump --no-owner "$ZOOLY_REMOTE_DB_URL" | \
psql "postgresql://postgres:password@localhost:5432/zooly2_local?sslmode=disable"
Using intermediate file:
# Step 1: Dump remote database to file
pg_dump --no-owner "postgresql://remote_user:password@remote_host:port/remote_db?sslmode=require" > remote_backup.sql
# Step 2: Restore to local database
psql "postgresql://postgres:password@localhost:5432/zooly2_local?sslmode=disable" < remote_backup.sql
After copying the database, ensure pgvector is enabled:
psql -U postgres -d zooly2_local -c "CREATE EXTENSION IF NOT EXISTS vector;"
To copy your local database to a remote server:
pg_dump --no-owner "postgresql://postgres:password@localhost:5432/zooly2_local?sslmode=disable" | \
psql "postgresql://remote_user:password@remote_host:port/remote_db?sslmode=require"