Skip to content

Instantly share code, notes, and snippets.

@tanraya
Created August 14, 2013 01:01
Show Gist options
  • Select an option

  • Save tanraya/6227167 to your computer and use it in GitHub Desktop.

Select an option

Save tanraya/6227167 to your computer and use it in GitHub Desktop.
Synchronize postgres production database with local development. NOTE: you need to create .pgpass file on production first.
ssh er -t 'pg_dump -h localhost -U estrabota estrabota_production | gzip > /tmp/estrabota.gz'
scp er:/tmp/estrabota.gz ./tmp
psql -U postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'estrabota_development';"
psql -U postgres -c "DROP DATABASE estrabota_development;"
psql -U postgres -c "CREATE DATABASE estrabota_development WITH TEMPLATE = template0 ENCODING = 'UNICODE' OWNER estrabota;"
gunzip -c ./tmp/estrabota.gz | psql -U postgres estrabota_development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment