Deep-dive on the Next Gen Platform. Join the Webinar!

Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Node.js Behavior in Heroku
      • Working with Node.js
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • Working with PHP
      • PHP Behavior in Heroku
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Working with AI
    • Heroku Inference
      • AI Models
      • Inference Essentials
      • Inference API
      • Quick Start Guides
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Databases & Data Management
  • Heroku Postgres
  • Postgres Basics
  • Provisioning Heroku Postgres

Provisioning Heroku Postgres

English — 日本語に切り替える

Last updated March 17, 2025

Table of Contents

  • Before Provisioning
  • Provision the Add-on
  • Application Config Vars
  • Designating a Primary Database
  • Sharing Heroku Postgres Between Applications
  • Removing the Add-on
  • Next Steps

Before Provisioning

Before you provision Heroku Postgres, confirm that it isn’t already provisioned for your app. Heroku automatically provisions Postgres for apps that include certain libraries if you created your account before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account.

Use the heroku addons command to determine whether your app has already provisioned Heroku Postgres:

$ heroku addons
Add-on                                               Plan         Price     State
───────────────────────────────────────────────────  ───────────  ────────  ───────
heroku-postgresql (postgresql-concave-52656)         essential-0  $5/month  created

Provision the Add-on

If heroku-postgresql isn’t in your app’s list of add-ons, you can provision it with the CLI command:

$ heroku addons:create heroku-postgresql:<PLAN_NAME> -a <APP_NAME>

For example, to provision an Essential-0 plan database:

$ heroku addons:create heroku-postgresql:essential-0 -a example-app
Creating heroku-postgresql:essential-0 on ⬢ example-app... ~$0.007/hour (max $5/month)
Database should be available soon
postgresql-concave-52656 is being created in the background. The app will restart when complete...
Use heroku addons:info postgresql-concave-52656 to check creation progress
Use heroku addons:docs heroku-postgresql to view documentation

Specify the Version

You can specify the version of Postgres you want to provision by including the --version flag in your provisioning command:

The addons:create example follows the syntax for Heroku CLI v9.0.0 or later. If you’re on v8.11.5 or earlier, use the command:

$ heroku addons:create heroku-postgresql:<PLAN_NAME> --version=15
$ heroku addons:create heroku-postgresql:<PLAN_NAME> -- --version=15

Learn more about PostgreSQL version support.

Depending on the plan you choose, your database can take up to 5 minutes to become available. You can track its status with the heroku pg:wait command, which blocks until your database is ready to use.

Blocking Logs

At add-on creation time, you can pass a flag to prevent logging of queries that get run against the database. If you turn this option on, you can’t turn it off after provisioning the database. To turn it off after you turned it on, you must migrate to a new database.

Blocking the queries in the logs reduces Heroku’s ability to help debug applications and tune application performance.

 

The addons:create example follows the syntax for Heroku CLI v9.0.0 or later. If you’re on v8.11.5 or earlier, use the command:

$ heroku addons:create heroku-postgresql:standard-0 -a example-app --block-logs
$ heroku addons:create heroku-postgresql:standard-0 -a example-app -- --block-logs

Application Config Vars

As part of the provisioning process, a DATABASE_URL config var is added to your app’s configuration. DATABASE_URL contains the URL your app uses to access the database. If your app already has a Heroku Postgres database and you provision another one, this config var’s name instead has the format HEROKU_POSTGRESQL_<COLOR>_URL (for example, HEROKU_POSTGRESQL_YELLOW_URL).

You can confirm the names and values of your app’s config vars with the heroku config command.

The value of your app’s DATABASE_URL config var can change at any time. Don’t rely on this value either inside or outside your Heroku app.

At this point, an empty PostgreSQL database is provisioned. To populate it with data from an existing data source, see the import instructions or follow the language-specific instructions to connect from your application.

Designating a Primary Database

The DATABASE_URL config var designates the URL of an app’s primary Heroku Postgres database. For apps with a single database, its URL is automatically assigned to this config var.

For apps with multiple Postgres databases, set the primary database with heroku pg:promote. Common use cases include leader-follower high-availability setups or as part of the database upgrade process.

Sharing Heroku Postgres Between Applications

You can share a single Heroku Postgres database between multiple apps with the heroku addons:attach command. You can also specify an alias for your add-on using the --as flag.:

$ heroku addons:attach my-originating-app::DATABASE --app example-app --as ATTACHED_DB
Attaching postgresql-addon-name to example-app... done
Setting ATTACHED_DB vars and restarting example-app... done, v11

By default, the attached database’s URL is assigned to a config var with the name format HEROKU_POSTGRESQL_<COLOR>_URL. In the example, since an alias was set, the config var’s name is ATTACHED_DB.

A shared database isn’t necessarily the primary database for any given app that it’s shared with. To promote a shared database, use the same command that you use for any other database.

To stop sharing your Heroku Postgres instance with another app, use the heroku addons:detach command:

$ heroku addons:detach ATTACHED_DB --app example-app
Detaching ATTACHED_DB to postgresql-addon-name from example-app... done
Unsetting ATTACHED_DB config vars and restarting example-app... done, v11

Removing the Add-on

You can delete the add-on using the Heroku dashboard or using the CLI.

If you’ve deprovisioned your database and want it restored, we may be able to restore it within the stated continuous protection rollback period. Beyond this window, it’s unlikely we can restore your database. Open a support ticket for assistance.

We recommend that you create backups of your data before deprovisioning. You can use PG Backups to take a snapshot of your data and download your backup to store in an external storage service. You can also export your data before deprovisioning.

Delete Using the Dashboard

To delete a Postgres database from the Heroku Dashboard:

  1. From the Heroku Dashboard, navigate to your application and then select the Resources tab.
  2. Select the Heroku Postgres add-on you want to delete, choose the dropdown on the right, and select Delete Add-on.
  3. On the Remove Add-on page, enter the app’s name to confirm, and select Remove add-on.

Delete Using the CLI

To remove your Heroku Postgres database, use the following command:

$ heroku addons:destroy heroku-postgresql

If you have two databases of the same type you must remove the add-on using its config var name. For example, to remove the HEROKU_POSTGRESQL_GRAY_URL database, run the command:

$ heroku addons:destroy HEROKU_POSTGRESQL_GRAY

If the removed database was the same one used in DATABASE_URL, that DATABASE_URL config var is unset on the app.

Next Steps

For information on how to connect to your Postgres database, see Connecting to Heroku Postgres.

Keep reading

  • Postgres Basics

Feedback

Log in to submit feedback.

Upgrading the Version of a Heroku Postgres Database Sharing Query Results with Dataclips

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices