Skip Navigation
Show nav
Heroku Dev Center Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
Heroku Dev Center Dev Center
  • 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 in or Sign 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
    • Buildpacks
  • Developer Tools
    • AI 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
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
        • Working with Rails
      • 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
    • Inference Essentials
    • Inference API
    • Inference Quick Start Guides
    • AI Models
    • Tool Use
    • AI Integrations
    • Vector Database
  • 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
  • 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
    • Heroku AppLink
      • Working with Heroku AppLink
      • Heroku AppLink Reference
      • Getting Started with Heroku AppLink
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Other Salesforce Integrations
  • Databases & Data Management
  • Heroku Postgres
  • Postgres Basics
  • Provisioning Heroku Postgres

Provisioning Heroku Postgres

English — 日本語に切り替える

Table of Contents [expand]

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

Last updated March 26, 2026

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        Max price  State
 ───────────────────────────────────────────────────── ───────────── ──────────── ────────── ───────
 heroku-postgresql (postgresql-concave-52656)            essential-0   ~$0.007/hour $5/month   created
  └─ as DATABASE

Provision the Add-on

To provision a new heroku-postgresql add-on, use the addons:create 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

Depending on the plan, 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.

After 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.

Specify the Postgres Version

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

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

Learn more about PostgreSQL version support.

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.

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

Application Config Vars

As part of the provisioning process, Heroku Postgres adds a new config var to your app’s configuration that includes the connection string to access the database. The config var name matches the attachment name for your database.

You can specify an attachment name when provisioning your database with addons:create and the --as flag:

$ heroku addons:create heroku-postgresql:essential-0 --as ANALYTICS_DATABASE -a example-app

Heroku Postgres uses the DATABASE attachment name and the DATABASE_URL config var by default. If your app already has a Heroku Postgres database attached as 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 values in the connection string of your database’s config var can change at any time. Ensure that your app reads your database’s config var to get the database’s connection string. Don’t rely on this value either inside or outside your Heroku app.

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 the attachment name as 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_URL.

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

Destroying the Add-on

You can destroy 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 Heroku PGBackups 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.

Destroy Using the Dashboard

To destroy 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.

Destroy Using the CLI

To destroy a Heroku Postgres database, use the addons:destroy command and specify the add-on name, config var, or attachment name of the database:

$ heroku addons:destroy postgresql-concave-52656

Or:

$ heroku addons:destroy DATABASE_URL

Next Steps

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

Feedback

Log in to submit feedback.

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
  • © 2026 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