Skip to content

Instantly share code, notes, and snippets.

@nathancolgate
Created December 16, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathancolgate/2364f2132099c7168d7476667109370d to your computer and use it in GitHub Desktop.
Save nathancolgate/2364f2132099c7168d7476667109370d to your computer and use it in GitHub Desktop.
Migrating postgres database from one server to another through tunnels
# Open SSH tunnels to both servers, routing postgres traffic to local port
# I use SSH Tunnel app for that, but I'm pretty sure you could figure out how to
# run that tunnel in the command line
# First: Dump the old DB
pg_dump -U deploy -h 127.0.0.1 -p 3303 -d my_app_production -F c -f outfile.sqlc
# It will prompt you for the user's password, and then you should be golden.
# -U username
# -h host (localhost)
# -p port (whatever port your ssh tunnel is running to)
# -d database (name of the remote database)
# -F format (c for custom)
# -f output file
# Last: Populate the new DB
pg_restore -U deploy -h 127.0.0.1 -p 3313 -d my_app_production -F c outfile.sqlc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment