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

    Visit the Heroku Blog

    Find news and updates from Heroku in the 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
      • Node.js Behavior in Heroku
      • 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
      • 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
    • Model Context Protocol
    • Vector Database
    • Heroku Inference
      • Inference Essentials
      • AI Models
      • Inference API
      • Quick Start Guides
    • 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
  • Databases & Data Management
  • Heroku Postgres
  • Postgres Basics
  • Testing PostgreSQL Major Version Upgrades

Testing PostgreSQL Major Version Upgrades

English — 日本語に切り替える

Last updated November 01, 2024

Table of Contents

  • Testing a PostgreSQL Version Upgrade with pg:upgrade
  • Testing a PostgreSQL Version Upgrade with pg:copy

Heroku recommends testing major PostgreSQL version upgrades for your Heroku Postgres add-ons before completing the upgrade in your production database.

Testing version upgrades helps identify any possible upgrade errors or incompatibility issues that could impact your database or application. Testing helps reduce the downtime for your application when you’re upgrading the production database.

The most common upgrade issues are related to type incompatibilities between PostgreSQL versions, object reference or dependency errors, or general application problems when an app or its PostgreSQL driver version doesn’t support the target PostgreSQL version.

Testing a PostgreSQL Version Upgrade with pg:upgrade

The pg:upgrade method is recommended for all Heroku Postgres databases, except for deprecated mini and basic plans.

Performing a PostgreSQL version upgrade with pg:upgrade requires app downtime on the order of 30 minutes. If your upgrade takes longer than 30 minutes, open a Support ticket.

To test the upgrade process, fork your existing production database on a non-production app to run and validate the complete upgrade process.

The following creates a fork of your production database on a staging or non-production app:

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:<database_plan> --fork production_app_name::DATABASE_URL --as PROD_DB_FORK -a staging_app_name
$ heroku addons:create heroku-postgresql:<database_plan> --as PROD_DB_FORK -a staging_app_name -- --fork production_app_name::DATABASE_URL

When the forked database is ready, start the version upgrade process and create a follower for it.

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:<database_plan> --follow staging_app_name::PROD_DB_FORK --as TEST_UPGRADE_FOLLOWER --app staging_app_name
$ heroku addons:create heroku-postgresql:<database_plan> --as TEST_UPGRADE_FOLLOWER --app staging_app_name -- --follow staging_app_name::PROD_DB_FORK staging_app_name

Follow the steps in the article to upgrade the testing follower. To complete the database version upgrade test, promote the upgraded database as the primary database for your non-production application. Verify that your application can connect and communicate with the database as expected.

$ heroku pg:promote TEST_UPGRADE_FOLLOWER --app staging_app_name

This approach lets you test the complete upgrade process and estimate how long your upgrade takes when you upgrade in production. This process is also helpful to confirm that your application is compatible with the new PG version, which is the case unless your application uses an old PostgreSQL client or driver.

When you’re finished testing the upgrade, you can delete the forked database and the upgraded follower.

Alternative Testing Approach

To speed up the version upgrade testing process, another approach is to create a follower of your production application in a non-production environment. You can run pg:upgrade on the follower directly.

Promote the upgraded database as the primary database in your non-production environment to verify that your application is compatible with the new version.

Testing a PostgreSQL Version Upgrade with pg:copy

Use the pg:copy method to upgrade the PostgreSQL versions of databases under 10 GB.

Performing a PostgreSQL version upgrade with pg:copy requires downtime of about 3 minutes per GB, although this amount can vary substantially.

To test the upgrade process, provision a new database on a non-production application, specifying the target PostgreSQL version:

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:<database_plan> --version=15 --as DATABASE_UPGRADE_TEST --app staging_app_name
$ heroku addons:create heroku-postgresql:<database_plan> --as DATABASE_UPGRADE_TEST --app staging_app_name -- --version=15

When the new database is available, copy the data from your production database to the new database:

$ heroku pg:copy production_app_name::DATABASE_URL DATABASE_UPGRADE_TEST --app staging_app_name

After the data copy finishes, promote the database to your non-production application to verify that your application is compatible with the new version:

$ heroku pg:promote DATABASE_UPGRADE_TEST --app staging_app_name

If the data copy process fails, check the error details in the logs available through heroku pg:backups:info <COPY_ID>.

Keep reading

  • Postgres Basics

Feedback

Log in to submit feedback.

Upgrading the Version of a Heroku Postgres Database Upgrading the Version of a Heroku Postgres Database

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