Upgrading Postgres in a Rails codebase

If you’re looking to upgrade Postgres locally in a Rails project, it’s straight-forward-yet-not-simple. It’s not a one-click/one-command operation.

I used the pg_dump command, along with Homebrew in this example. I have also seen a good post from Christopher Brown and Keita on manually backing up and copying data files using pg_upgrade. These involve a few more steps that I personally did not need. YMMV, so these are solid alternatives if needed.

  1. Backup your data.
    Run pg_dump for all databases that you’d like to backup:
    $ cd /your/project/root
    $ pg_dump your-database-name > choose-a-backup-file-name
  2. Upgrade your Postgres version.
    1. For Homebrew users:
      Verify the version you currently have installed:
      $ brew list --versions postgres or $ psql --version
      $ brew update && brew upgrade postgres
  3. Verify your Postgres upgrade.
    $ brew list --versions postgres or $ psql --version
  4. Create your database(s).
    rake db:create
  5. Restore your data.
    psql your-database-name < your-backup-file

Your Thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s