My Heroku Cheatsheet

My Heroku Cheatsheet

You can find all this in the Heroku docs, I’m just filtering out the stuff I use very frequently. I will keep updating this so check back later. ALl of my examples include the -a myapp at the end because 95% of my apps have both staging and production environments so I have gotten in the habit of using this option.

Heroku Postgres DB

Download current database:

heroku pgbackups:capture --expire
curl -o latest.dump `heroku pgbackups:url`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d myapp_development latest.dump

Psql console:

heroku pg:psql -a myapp

Bloat:

heroku pg:bloat DATABASE_URL -a myapp

Vacuum stat:

heroku pg:vacuum_stats DATABASE_URL -a myapp

Deploying

Put the app into maintenance mode:

heroku maintenance:on -a myapp
heroku scale worker=0 -a myapp

Normal push:

git push heroku master

Push another branch ( I ALWAYS forget this)

git push heroku yourbranch:master

Bring it back:

heroku maintenance:off -a myapp
heroku scale worker=2 -a myapp # 2 or whatever number is your normal worker count.

Running stuff

Rails console:

heroku run rails console -a myapp

Run a rake task in the background:

heroku run:detached rake migration:photos -a myapp

Debugging

I-dont-always-test-my-code-But-when-I-do-I-do-it-in-production

Tail the log

heroku logs --tail -a myapp

Just app logs:

heroku logs --source app --tail  -a myapp

Just the workers

heroku logs -p worker -t -a myapp

Just the web

heroku logs -p web -t -a myapp


References:
https://devcenter.heroku.com/articles/git
https://devcenter.heroku.com/articles/heroku-postgres-database-tuning
https://devcenter.heroku.com/articles/pgbackups
https://devcenter.heroku.com/articles/logging