Getting Started on Heroku with Ruby (Microsoft Windows)
Introduction
Complete this tutorial to develop a sample Ruby app with JRuby in a local Microsoft Windows development environment and deploy it to Heroku.
If you’re not on Windows, follow the Getting Started with Ruby on Heroku guide.
The tutorial assumes that you have:
- A verified Heroku Account
- JDK 8 installed locally to get a Java virtual machine (JVM).
- JRuby 9.4.1.0 installed locally.
- Bundler installed locally. You can install it in a command prompt with
jruby -S gem install bundler
.
If you receive an error such as 'jruby' is not recognized as an internal or external command, operable program or batch file.
, close your terminal session and open a new terminal to ensure that the %PATH%
environment variable is set correctly.
Using dynos and databases to complete this tutorial counts towards your usage. We recommend using our low-cost plans to complete this tutorial. Eligible students can apply for platform credits through our new Heroku for GitHub Students program.
Set Up
The Heroku CLI requires Git, the popular version control system. If you don’t have Git installed, complete the following before proceeding:
Install the Heroku Command Line Interface (CLI). You can use the CLI to manage and scale your applications, provision add-ons, view your logs, and run your application locally.
Download the appropriate installer for your Windows installation:
After installation, you can use the heroku
command from your command shell.
To log in to the Heroku CLI, use the heroku login
command:
> heroku login
heroku: Press any key to open up the browser to login or q to exit
› Warning: If browser does not open, visit
› https://cli-auth.heroku.com/auth/browser/***
heroku: Waiting for login...
Logging in... done
Logged in as me@example.com
This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, click the Log in
button on the page.
This authentication is required for the heroku
and git
commands to work correctly.
If you’re behind a firewall that uses a proxy to connect with external HTTP/HTTPS services, set the HTTP_PROXY
or HTTPS_PROXY
environment variables in your local development environment before running the heroku
command.
Clone the Sample App
If you’re new to Heroku, it’s recommended that you complete this tutorial using the Heroku-provided sample application.
If you have an existing application you want to deploy, follow this article instead.
Clone the sample application so that you have a local version of the code. Execute these commands in your local command shell or terminal:
> git clone https://github.com/heroku/jruby-getting-started.git
> cd jruby-getting-started
You now have a functioning git repository that contains a simple application. It includes a Gemfile
file, which Ruby’s dependency manager, bundler
, uses to install dependencies.
Create Your App
Using a dyno and a database to complete this tutorial counts towards your usage. Delete your app, and database as soon as you’re done to control costs.
Apps use Eco dynos if you’re subscribed to Eco by default. Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account. It’s recommended if you plan on deploying many small apps to Heroku. Learn more here. Eligible students can apply for platform credits through our Heroku for GitHub Students program.
Create an app on Heroku to prepare the platform to receive your source code:
$ heroku create
Creating app... done, ⬢ polar-inlet-4930
http://polar-inlet-4930.herokuapp.com/ | https://git.heroku.com/polar-inlet-4930.git
When you create an app, a git remote called heroku
is also created and associated with your local git repository. Git remotes are versions of your repository that live on other servers. You deploy your app by pushing its code to that special Heroku-hosted remote associated with your app.
Heroku generates a random name for your app, in this case, polar-inlet-4930
. You can specify your own app name.
Define a Procfile
Use a Procfile, a text file in the root directory of your application, to explicitly declare what command to execute to start your app.
The Procfile
in the example app looks like this:
web: bundle exec puma -C config/puma.rb
This Procfile declares a single process type, web
, and the command needed to run it. The name web
is important here. It declares that this process type is attached to Heroku’s HTTP routing stack and receives web traffic when deployed. The command used here runs Puma, the web server, and passes in a configuration file.
A Procfile can contain additional process types. For example, you can declare a background worker process that processes items off a queue.
The example project also contains a Procfile.windows
file, which contains the line, web: jruby -S bin\puma -C config\puma.rb
.
This file is necessary because the command used to run the application on Windows is different from the one used to run the application on Heroku, which is Linux-based.
Provision a Database
The sample Rails app requires a database. Provision a Heroku Postgres database, one of the add-ons available through the Elements Marketplace. Add-ons are cloud services that provide out-of-the-box additional services for your application, such as logging, monitoring, databases, and more.
An essential-0
Postgres size costs $5 a month, prorated to the minute. At the end of this tutorial, we prompt you to delete your database to minimize costs.
$ heroku addons:create heroku-postgresql:essential-0
Creating heroku-postgresql:essential-0 on ⬢ polar-inlet-4930... ~$0.007/hour (max $5/month)
Database should be available soon
postgresql-encircled-75487 is being created in the background. The app will restart when complete...
Use heroku addons:info postgresql-encircled-75487 to check creation progress
Use heroku addons:docs heroku-postgresql to view documentation
Your Heroku app can now access this Postgres database. The DATABASE_URL
environment variable stores your credentials, which Rails connects to by convention. You can see all the add-ons provisioned with the addons
command:
$ heroku addons
Add-on Plan Price State
────────────────────────────────────────────── ─────────── ──────── ───────
heroku-postgresql (postgresql-encircled-75487) essential-0 $5/month created
└─ as DATABASE
The table above shows add-ons and the attachments to the current app (polar-inlet-4930) or other apps.
Deploy the App
Deploy your code. This command pushes the main
branch of the sample repo to your heroku
remote, which then deploys to Heroku:
> git push heroku main
$ git push heroku main
Enumerating objects: 282, done.
Counting objects: 100% (282/282), done.
Delta compression using up to 16 threads
Compressing objects: 100% (175/175), done.
Writing objects: 100% (282/282), 56.28 KiB | 7.04 MiB/s, done.
Total 282 (delta 103), reused 232 (delta 86), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-22 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Ruby app detected
remote:
remote: ## Warning: Your app needs java
remote:
remote: The Ruby buildpack determined your app needs java installed
remote: we recommend you add the jvm buildpack to your application:
remote:
remote: $ heroku buildpacks:add heroku/jvm --index=1
remote:
remote: -----> Installing Java
remote:
remote: -----> Downloading Buildpack: heroku/jvm
remote: -----> Detected Framework: JVM Common
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Installing bundler 2.3.25
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.1.0-jruby-9.4.1.0
remote: -----> Installing dependencies using bundler 2.3.25
remote: Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
...
remote: Bundled gems are installed into `./vendor/bundle`
remote: Bundle completed (109.67s)
remote: Cleaning up the bundler cache.
remote: -----> Installing node-v16.18.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
...
remote: Asset precompilation completed (18.27s)
remote: Cleaning assets
remote: Running: rake assets:clean
remote: -----> Detecting rails configuration
remote:
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote: Default types for buildpack -> console, rake
remote:
remote: -----> Compressing...
remote: Done: 147.6M
remote: -----> Launching...
remote: ! The following add-ons were automatically provisioned: heroku-postgresql. These add-ons may incur additional cost, which is prorated to the second. Run `heroku addons` for more info.
remote: Released v6
remote: https://polar-inlet-4930.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/polar-inlet-4930.git
* [new branch] main -> main
The application is now deployed. Ensure that at least one instance of the app is running:
> heroku ps:scale web=1
Visit the app at the URL shown in the logs. As a handy shortcut, you can also open the website as follows:
$ heroku open
View Logs
Heroku treats logs as streams of time-ordered events, aggregated from the output streams of all your app and Heroku components. Heroku provides a single stream for all events.
View information about your running app by using one of the logging commands, heroku logs --tail
:
> heroku logs --tail
2023-03-07T18:17:20.056546+00:00 heroku[web.1]: State changed from crashed to starting
2023-03-07T18:17:28.388264+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2023-03-07T18:17:29.421644+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2023-03-07T18:17:29.456159+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2023-03-07T18:17:35.000000+00:00 app[api]: Build succeeded
2023-03-07T18:17:35.498806+00:00 app[web.1]: Puma starting in single mode...
2023-03-07T18:17:35.499821+00:00 app[web.1]: * Puma version: 6.1.1 (jruby 9.4.1.0 - ruby 3.1.0) ("The Way Up")
2023-03-07T18:17:35.500730+00:00 app[web.1]: * Min threads: 5
2023-03-07T18:17:35.501612+00:00 app[web.1]: * Max threads: 5
2023-03-07T18:17:35.502174+00:00 app[web.1]: * Environment: production
2023-03-07T18:17:35.503200+00:00 app[web.1]: * PID: 2
2023-03-07T18:17:42.977653+00:00 app[web.1]: * Listening on http://[::]:53483
2023-03-07T18:17:43.026824+00:00 app[web.1]: Use Ctrl-C to stop
2023-03-07T18:17:43.504644+00:00 heroku[web.1]: State changed from starting to up
To see more log messages generate, visit your application in the browser first.
To stop streaming the logs, press Control+C
.
Scale the App
After deploying the sample app, it automatically runs on a single web dyno. Think of a dyno as a lightweight container that runs the command specified in the Procfile
.
You can check how many dynos are running by using the ps
command:
> heroku ps
=== web (Eco): `web: bundle exec puma -C config/puma.rb`
web.1: up 2023/03/07 12:42:34 (~ 23m ago)
Scaling an application on Heroku is equivalent to changing the number of running dynos. Scale the number of web dynos to zero:
$ heroku ps:scale web=0
Access the app again by hitting refresh in your browser, or heroku open
to open it in a web tab. You get an error message because you no longer have web dynos available to serve requests.
Scale it up again:
$ heroku ps:scale web=1
By default, apps use Eco dynos if you’re subscribed to Eco. Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Eco dynos sleep if they don’t receive any traffic for half an hour. This sleep behavior causes a few seconds delay for the first request upon waking. Eco dynos consume from a monthly, account-level quota of eco dyno hours. As long as you haven’t exhausted the quota, your apps can continue to run.
To avoid dyno sleeping, upgrade to a Basic or higher dyno type as described in the Dyno Types article. Upgrading to at least Standard dynos allows you to scale up to multiple dynos per process type.
Declare App Dependencies
Heroku recognizes an app as a Ruby app by the existence of a Gemfile
file in the root directory.
The demo app you deployed already has a Gemfile
, and it looks something like this:
source 'https://rubygems.org'
ruby '3.1.0', engine: 'jruby', engine_version: '9.4.1.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 7.0.4.2'
...
The Gemfile
file specifies the dependencies to install with your application. It also determines the version of Ruby used to run your application on Heroku.
When an app deploys, Heroku reads this file and installs the appropriate Ruby version and dependencies using the bundle install
command.
To run the app locally, you must also install dependencies locally. Run bundle install
in your local directory to install the dependencies:
> jruby -S bundle install --binstubs
Using rake 13.0.6
Using concurrent-ruby 1.2.2
Using i18n 1.12.0
Using minitest 5.18.0
Using tzinfo 2.0.6
Using activesupport 7.0.4.2
Using builder 3.2.4
Using erubi 1.12.0
Using racc 1.6.2 (java)
Using nokogiri 1.14.2 (java)
....
Using puma 6.1.1 (java)
Your bundle is complete!
If you receive the error No such file or directory -- bundle (LoadError)
, make sure that you executed jruby -S gem install bundler
as described in the introduction.
Running the App Locally
Running apps locally in your own dev environment requires some effort. Rails typically requires a database and the sample application uses Postgres. You must follow the instructions for installing Postgres locally. When installing Postgres, take note of the password you set for the default user.
Open the config\database.yml
file and set the username and password for your local (development) database. Look for these lines:
development:
<<: *default
database: ruby-getting-started_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: ruby-getting-started
# The password associated with the postgres role (username).
#password:
Modify the username and password by replacing the password with the one you set up while installing Postgres:
username: postgres
# The password associated with the postgres role (username).
password: postgres
Repeat this step for the ruby-getting-started_test
database, in the test:
section below the development database entry.
You can create the appropriate database and tables for the app using this rake
task:
> jruby -S bin\rake db:create db:migrate
== 20140707111715 CreateWidgets: migrating ====================================
-- create_table(:widgets)
-> 0.0076s
== 20140707111715 CreateWidgets: migrated (0.0077s) ===========================
Now start your application locally using the heroku local
command, which is part of the Heroku CLI:
> heroku local --port 5001 -f Procfile.windows
[OKAY] Loaded ENV .env File as KEY=VALUE Format
12:26:42 PM web.1 | Puma starting in single mode...
12:26:42 PM web.1 | * Puma version: 6.1.1 (jruby 9.4.1.0 - ruby 3.1.0) ("The Way Up")
12:26:42 PM web.1 | * Min threads: 5
12:26:42 PM web.1 | * Max threads: 5
12:26:42 PM web.1 | * Environment: development
12:26:42 PM web.1 | * PID: 35023
12:26:46 PM web.1 | * Listening on http://[::]:5001
12:26:46 PM web.1 | Use Ctrl-C to stop
The -f Procfile.windows
flag ensures your Windows-specific Procfile is picked up. The example project contains a Procfile.windows
file, which contains the line, web: jruby -S bin\puma -C config\puma.rb
. This file is necessary because the command used to run the application on Windows is different from the one used to run the application on Heroku, which is Linux-based. Just like Heroku, heroku local
examines the Procfile to determine what to run.
To see your app running locally, open http://localhost:5001 with your web browser.
To stop the app from running locally, in the CLI, press Control + C
to exit.
Push Local Changes
In this step, you propagate a local change to the application to Heroku.
Modify Gemfile
to include an additional dependency for the cowsay
gem:
gem 'cowsay'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 7.0.4.2'
...
Modify app/views/welcome/index.erb
to use this gem. Change your code to look like this:
<h1>Getting Started with Ruby</h1>
<p>
Welcome!
</p>
<pre><%= Cowsay.say("Hello", "tux") %></pre>
Now test locally:
> jruby -S bundle install
> heroku local --port 5001 -f Procfile.windows
Visit your application at http://localhost:5001 to see an ASCII picture displayed.
Now, deploy this local change to Heroku.
Almost every deploy to Heroku follows the same pattern. First, add the modified files to your local Git repository:
> git add .
Now commit the changes to the repository:
> git commit -m "Demo"
Now deploy as you did before:
> git push heroku main
Finally, check that everything is working:
> heroku open
Provision a Logging Add-on
Beyond databases, add-ons provide many additional services for your application. In this step, you provision a free add-on to store your app’s logs.
By default, Heroku stores 1500 lines of logs from your application, but the full log stream is available as a service. Several add-on providers have logging services that provide things such as log persistence, search, and email and SMS alerts.
In this step, you provision one of these logging add-ons, Papertrail.
Provision the papertrail logging add-on:
> heroku addons:create papertrail
Creating papertrail on ⬢ polar-inlet-4930... free
Welcome to Papertrail. Questions and ideas are welcome (technicalsupport@solarwinds.com). Happy logging!
Created papertrail-horizontal-77903 as PAPERTRAIL_API_TOKEN
Use heroku addons:docs papertrail to view documentation
The add-on is now deployed and configured for your application. You can list add-ons for your app with this command:
$ heroku addons
To see this particular add-on in action, visit your application’s Heroku URL a few times. Each visit generates more log messages, which get routed to the Papertrail add-on. Visit the Papertrail console to see the log messages:
$ heroku addons:open papertrail
Your browser opens up a Papertrail web console, showing the latest log events. The interface lets you search and set up alerts.
Start a Console
You can run a command, typically scripts and applications that are part of your app, in a one-off dyno using the heroku run
command. You can also launch a REPL process attached to your local terminal for experimenting in your app’s environment:
> heroku run jirb
Running jirb on ⬢ polar-inlet-4930... up, run.4883 (Eco)
irb(main):001:0>
If you receive an error, Error connecting to process
, configure your firewall.
When the console starts, it loads your entire app. For example, you can type puts Cowsay.say("hi", "Cow")
and an animal saying “hi” displays. Type exit
to quit the console.
irb(main):001:0> require 'cowsay'
require 'cowsay'
=> true
irb(main):002:0> puts Cowsay.say("Hello", "tux")
_______
| Hello |
-------
\
\
.--.
|o_o |
|:_/ |
// \ \
(| | )
/'\_ _/`\
\___)=(___/
=> nil
irb(main):003:0> exit
Let’s try another example. Create another one-off dyno and run the bash
command to open up a shell on that dyno. You can then execute commands there. Each dyno has its own ephemeral filespace, populated with your app and its dependencies. After the command completes, in this case, bash
, the dyno terminates:
> heroku run bash
Running `bash` attached to terminal... up, run.1421
~ $ ls
app bin config config.ru db Gemfile Gemfile.lock last_pack_release.out lib log Procfile Procfile.windows public Rakefile README.md test tmp vendor
~ $ exit
exit
Don’t forget to type exit
to exit the shell and terminate the dyno.
Define Config Vars
Heroku lets you externalize configuration by storing data such as encryption keys or external resource addresses in config vars.
At runtime, config vars are exposed as environment variables to the application. For example, modify app/views/welcome/index.erb
so that the method repeats an action depending on the value of the TIMES
environment variable. Change the file so that its first few lines read as follows:
<h1>Getting Started with Ruby</h1>
<p>
Welcome!
</p>
<% for i in 0..(ENV['TIMES'] ? ENV['TIMES'].to_i : 2) do %>
<p>Hello World #<%= i %>!</p>
<% end %>
heroku local
automatically sets up the environment based on the contents of the .env
file in your local directory. In the top-level directory of your sample project, there’s already a .env
file that contains:
TIMES=10
If you run the app with heroku local
, you see “Hello World” ten times.
To set the config var on Heroku, execute the following:
> heroku config:set TIMES=10
View the app’s config vars using heroku config
:
> heroku config
== polar-inlet-4930 Config Vars
PAPERTRAIL_API_TOKEN: erdKhPeeeehIcdfY7ne
TIMES: 10
To see this change in action, deploy your changed application to Heroku.
Use a Database
Listing the config vars for your app displays the URL that your app uses to connect to the database, DATABASE_URL
:
> heroku config
=== polar-inlet-4930 Config Vars
DATABASE_URL: postgres://xx:yyy@host:5432/d8slm9t7b5mjnd
HEROKU_POSTGRESQL_BROWN_URL: postgres://xx:yyy@host:5432/d8slm9t7b5mjnd
...
Heroku also provides a heroku pg
command that shows a lot more:
> heroku pg
=== DATABASE_URL
Plan: Essential 0
Status: Available
Connections: 0/20
PG Version: 15.5
Created: 2024-05-01 13:22 UTC
Data Size: 8.0 MB/1.00 GB (0.78%) (In compliance)
Tables: 3
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-elliptical-30581
This info shows an essential-0
database running Postgres v15.5, with three tables.
The example app you deployed already has database functionality. It has a controller and database model for widgets, used by your app’s ‘/widgets’ page. You can visit the page by appending ‘/widgets’ to your app’s URL.
If you visit the URL, you see an error page appear. Check out the error message using heroku logs
or in Papertrail to see something like this:
2023-03-07T18:32:40.112476+00:00 app[web.1]: I, [2023-03-07T18:32:40.111637 #2] INFO -- : [ba2011bf-3eda-446d-aa73-99469351542c] Started GET "/widgets" for 13.110.54.15 at 2023-03-07 18:32:40 +0000
2023-03-07T18:32:40.120417+00:00 app[web.1]: I, [2023-03-07T18:32:40.119956 #2] INFO -- : [ba2011bf-3eda-446d-aa73-99469351542c] Processing by WidgetsController#index as HTML
2023-03-07T18:32:40.709253+00:00 app[web.1]: I, [2023-03-07T18:32:40.708867 #2] INFO -- : [ba2011bf-3eda-446d-aa73-99469351542c] Rendered widgets/index.html.erb within layouts/application (Duration: 568.1ms | Allocations: 0)
2023-03-07T18:32:40.710008+00:00 app[web.1]: I, [2023-03-07T18:32:40.709695 #2] INFO -- : [ba2011bf-3eda-446d-aa73-99469351542c] Rendered layout layouts/application.html.erb (Duration: 569.2ms | Allocations: 0)
2023-03-07T18:32:40.712406+00:00 app[web.1]: I, [2023-03-07T18:32:40.712130 #2] INFO -- : [ba2011bf-3eda-446d-aa73-99469351542c] Completed 500 Internal Server Error in 591ms (ActiveRecord: 147.4ms | Allocations: 0)
2023-03-07T18:32:40.728894+00:00 app[web.1]: F, [2023-03-07T18:32:40.728559 #2] FATAL -- : [ba2011bf-3eda-446d-aa73-99469351542c]
2023-03-07T18:32:40.728896+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] ActionView::Template::Error (ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: relation "widgets" does not exist
2023-03-07T18:32:40.728896+00:00 app[web.1]: Position: 25):
2023-03-07T18:32:40.728897+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 12: </thead>
2023-03-07T18:32:40.728898+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 13:
2023-03-07T18:32:40.728898+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 14: <tbody>
2023-03-07T18:32:40.728898+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 15: <% @widgets.each do |widget| %>
2023-03-07T18:32:40.728898+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 16: <tr>
2023-03-07T18:32:40.728899+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 17: <td><%= widget.name %></td>
2023-03-07T18:32:40.728899+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] 18: <td><%= widget.description %></td>
2023-03-07T18:32:40.728899+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c]
2023-03-07T18:32:40.728901+00:00 app[web.1]: [ba2011bf-3eda-446d-aa73-99469351542c] app/views/widgets/index.html.erb:15
This error indicates that while we could connect to the database, the widgets
table wasn’t found. You can fix that error by running rake db:migrate
. To execute this command on Heroku, run it in a one-off dyno like so:
> heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.3559
Migrating to CreateWidgets (20140707111715)
== 20140707111715 CreateWidgets: migrating ====================================
-- create_table(:widgets)
-> 0.0244s
== 20140707111715 CreateWidgets: migrated (0.0247s) ===========================
Now if you visit the /widgets
page of your app again, you can list and create widget records.
If you have Postgres installed locally, you can also interact directly with the database. For example, here’s how to connect to the database using psql
and execute a query:
> heroku pg:psql
d8slm9t7b5mjnd=> select * from widgets;
id | name | description | stock | created_at | updated_at
----+-----------+--------------+-------+----------------------------+----------------------------
1 | My Widget | It's amazing | 100 | 2023-03-07 21:04:39.029311 | 2023-03-07 21:04:39.029311
(1 row)
Read more about Heroku PostgreSQL.
A similar technique can be used to install MongoDB or Redis add-ons.
Next Steps
You now know how to deploy an app, change its configuration, view logs, scale, and attach add-ons.
Here’s some recommended reading:
- Read How Heroku Works for a technical overview of the concepts you encounter while writing, configuring, deploying, and running applications.
- To learn more about developing and deploying Ruby applications, visit the Ruby support category.
Remember to delete your example app, and database as soon as you’re done with the tutorial, to control costs.
Delete Your App and Add-on
Remove the app and database from your account. You’re only charged for the resources you used.
This action removes your add-on and any data saved in the database.
$ heroku addons:destroy heroku-postgresql
▸ WARNING: Destructive Action
▸ This command will affect the app polar-inlet-4930
▸ To proceed, type polar-inlet-4930 or re-run this command with
▸ --confirm polar-inlet-4930
>
This action permanently deletes your application
$ heroku apps:destroy
▸ WARNING: This will delete ⬢ polar-inlet-4930 including all add-ons.
▸ To proceed, type polar-inlet-4930 or re-run this command with
▸ --confirm polar-inlet-4930
>
You can confirm that your add-on and app are gone with these commands:
$ heroku addons --all
$ heroku apps --all