Heroku Cheatsheet

by Giang, last updated 24 Apr 2018

Create App

Link a folder with an existing Heroku app:

heroku git:remote -a project

Logs

Log types and filters:

  • App logs: --source app
  • System logs: --source heroku
  • API logs: --source heroku --dyno api

Log format:

timestamp source[dyno]: message

# example
2010-09-16T15:13:46.677020+00:00 app[web.1]: Processing PostController#list (for 208.39.138.12 at 2010-09-16 15:13:46) [GET]
2010-09-16T15:13:46.677023+00:00 app[web.1]: Rendering template within layouts/application
2010-09-16T15:13:46.677902+00:00 app[web.1]: Rendering post/list
2010-09-16T15:13:46.678990+00:00 app[web.1]: Rendered includes/_header (0.1ms)
2010-09-16T15:13:46.698234+00:00 app[web.1]: Completed in 74ms (View: 31, DB: 40) | 200 OK [http://myapp.heroku.com/]
2010-09-16T15:13:46.723498+00:00 heroku[router]: at=info method=GET path="/posts" host=myapp.herokuapp.com" fwd="204.204.204.204" dyno=web.1 connect=1ms service=18ms status=200 bytes=975
2010-09-16T15:13:47.893472+00:00 app[worker.1]: 2 jobs processed at 16.6761 j/s, 0 failed ...

Commands:

# retrieve logs, 100 lines
heroku logs

# specify number of lines retrieved [--num / -n] max 1500 
heroku logs -n 200

# get realtime logs [--tail / -t]
heroku logs --tail

Postgresql

Common commands

# list backups
heroku pg:backups

# create a back up
heroku pg:backups:capture

# cancel backup
heroku pg:backups:cancel

# download latest backup
heroku pg:backups:download

# import backup to local database
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump

Domains

# list domains
heroku domains

# add domain
heroku domains:add www.example.com

# remove domain
heroku domains:remove www.example.com

Maintenance mode

heroku maintenance:on   # Enable maintenance mode
heroku maintenance:off  # Disable maintenance mode
heroku maintenance      # Check maintenance status