Sometimes you will need to perform maintenance on your Heroku application. In this post, I will take you through the two main ways I run ad-hoc commands on Heroku applications.
Running Commands with Heroku CLI
When I am on my machine, I use the Heroku command line interface.
All commands for Heroku CLI start with
heroku. To tell Heroku to run a command, you use
The full line you will need to run will look like
heroku run command_to_run arguments for command --app my_heroku_app
heroku runtells Heroku you want to run a command
command_to_run arguments for the commandis where you would put your full command, like you were running it locally
--app my_heroku_apptells Heroku which app you want to run the command on
If I had a Ruby on Rails application and I want to run the
db:seed command, I would write:
heroku run rails db:seed --app my_rails_app
When you run a command you will see it:
- Connecting to the appropriate instance
- Executing the command
- Returning any output
Running Commands on the Heroku Web Interface
If I am not on my machine, then I will use the web interface. The web interface is excellent, you can share guidance with your team without assuming anyone has set up the CLI tool.
To use the web console, navigate to your application in Heroku. The same application that you would pass into
In the top-right of the interface, there is a “More” button, pressing it displays a “Run Console” option. Select it to add your command.
In this case, we don’t need to type
heroku run or
--app my_heroku_app because Heroku knows both these things.
You can even bookmark the console by editing this link with your details: