Skip to content

Instantly share code, notes, and snippets.

@seejee
Last active January 19, 2017 16:30
Show Gist options
  • Save seejee/62b0536c7382289f59273038bef79066 to your computer and use it in GitHub Desktop.
Save seejee/62b0536c7382289f59273038bef79066 to your computer and use it in GitHub Desktop.
Database cutover instructions

Prep the new Heroku database

  • Add a Standard-4 Postgres database to the jetpack-prod Heroku app
  • Wait for it to initialize
  • heroku pg:psql -a jetpack-prod
  • CREATE EXTENSION hstore;
  • Take note of the new DATABASE_URL

Put the site in maintenance mode and shut down all servers

  • mina maintenance_up to=puma0 && mina maintenance_up
  • Shut down puma: mina pumastop to=puma0 && mina pumastop
  • Shut down delayed_job: On db0 -> script/delayed_job stop

Move the data to Heroku

  • On db0 in a tmux session
  • pg_dump --no-password --clean --no-owner --format c -f checklistpro.dump -d checklistpro (about 5-6 minutes)
  • pg_restore --exit-on-error --no-acl --no-owner -n public -d DATABASE_URL checklistpro.dump (about 10 minutes)
  • heroku pg:psql -a jetpack-prod
  • VACUUM ANALYZE (about 2-3 minutes)
  • Shut down postgres on db0 to ensure nothing is using it

Redeploy master to pick up DATABASE_URL change

  • Update DATABASE_URL in application.yml on all Digital Ocean servers (db0, puma0, arjjun)
  • mina deploy to=db0 && mina deploy to=puma0 && mina deploy
  • mina pumastart && mina pumastart to=puma0
  • mina maintenance_down to=puma0 && mina maintenance_down

Configure Heroku database backups

  • Add PGBackup job for 2AM Eastern
  • Add scheduled job to run VACUUM every night
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment