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
Hide 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
      • Working with Node.js
      • Troubleshooting Node.js Apps
      • Node.js Behavior in Heroku
    • 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
      • PHP Behavior in Heroku
      • Working with PHP
    • 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
  • 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
  • Language Support
  • Ruby
  • Ruby Behavior in Heroku
  • Ruby Database Auto-Provisioning

Ruby Database Auto-Provisioning

English — 日本語に切り替える

Last updated December 03, 2024

Table of Contents

  • Heroku Postgres Database Auto-Provisioning Behavior
  • Skip Auto-Provisioning a Database
  • Use a Different Database with Rails

A Heroku Postgres database is automatically provisioned by default for Ruby apps if certain conditions are met. This article covers how to opt out of this behavior and how to use a non-Heroku Postgres database.

This page isn’t applicable Fir-generation apps.

 

This article is only applicable to accounts created before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account.

Heroku Postgres Database Auto-Provisioning Behavior

Heroku buildpacks can auto-provision add-ons through the v2 buildpack release API. The heroku/ruby buildpack uses this API to request to provision a Heroku Postgres database if all of these conditions are true:

  • You created your account before May 15, 2023 or you asked Heroku Support to enable auto-provisioning for your account.
  • The heroku/ruby buildpack is the last buildpack to execute on the first deploy.
  • The HEROKU_SKIP_DATABASE_PROVISION environment variable isn’t set on the application.
  • Has one of these PostgreSQL gems in Gemfile.lock

Skip Auto-Provisioning a Database

Accounts created after May 15, 2023 don’t auto-provision databases for their apps unless you asked Heroku Support to the feature for your account.

If you created your account before that date or ask Support to enable auto-provisioning, you can opt out of auto-provisioning on a per-app basis by setting the HEROKU_SKIP_DATABASE_PROVISION environment variable to any value:

$ heroku config:set HEROKU_SKIP_DATABASE_PROVISION=1

This setting skips database auto-provisioning for that app. For Review Apps, you can set this config var in your pipeline setting’s Review app config vars section.

This environment variable affects only heroku/ruby users and only applications without a successful first deployment. You must manually remove the add-on on any applications already deployed with an auto-provisioned database.

This environment variable interface is experimental and subject to change. We emit deprecation warnings from the heroku/ruby buildpack on deployment with additional details before making any changes.

Use a Different Database with Rails

If you’re using a database other than Heroku Postgres, the behavior of provisioning a Postgres database for Rails apps can conflict with your configuration. When Heroku auto-provisions a Heroku Postgres database for your application, it sets theDATABASE_URL config var. With all versions of Rails on Heroku, any information present in the DATABASE_URL environment variable takes precedence. This behavior is problematic if you’re not using a Postgres database, as your application tries to connect to the auto-provisioned Heroku Postgres database by default.

If you want to use a non-Heroku Postgres database for your Rails app, opt out of database auto-provisioning.

If you don’t opt out of auto-provisioning, delete the auto-provisioned Postgres database.

For detailed information about how exactly your version of Rails connects to the database, see Rails database connection behavior.

Use a Different Database with Review Apps

You can dynamically assign the value of DATABASE_URL inside your code. You must assign this value before the database initializes. For example:

ENV["DATABASE_URL"] = "mysql://#{ ENV['MY_DATABASE_PASSWORD'] }:#{ ENV['MY_DATABASE_USERNAME'] }@#{ ENV['MY_DATABASE_HOST'] }"

You can place this code in an initializer or directly in your config/database.yml inside an ERB code section. The important thing is that this code runs before your application attempts to connect to the database.

Keep reading

  • Ruby Behavior in Heroku

Feedback

Log in to submit feedback.

Ruby Default Web Server Ruby Default Web Server

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