Chris Mendez in For Developers, Ruby, Heroku

Heroku: Upgrading your database

Here's a process I've found for upgrading your database on Heroku.

There are many more commands and I highly suggest reviewing the Heroku Documentation.

First, check the status of your databse.

heroku pg:info  

Set your app to maintenance mode.

heroku maintenance:on  

Create a backup of your current database.

heroku pgbackups capture  

Create a new instance of your database

heroku addons:add heroku-postgresql:standard-0  

Check the progress on the new database you've provisioned.

heroku pg:wait  

Restore the database

heroku pgbackups:restore DATABASE_URL  

Point to the new database by promoting it.

heroku pg:backups:promote DATABASE_URL  

Re-instate the app by turning off maintenance mode.

heroku maintenance:off  

Double check your work.

heroku pg:info  

Measuring the Health of Your Database

There is a tool called PG Extras that can help you measure the health of your database and application. It can give you insight on things such as load time, database usage, long queries, etc. Here are a few commands I use regularly.

Install PG Extras

heroku plugins:install heroku-pg-extras  

Index Usage

heroku pg:index_usage  

Number of processes running

heroku pg:ps  

Calculate the index sizes

heroku pg:index_size  

Long Running Queries

heroku pg:long_running_queries  

Resources