Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • 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
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
    • Single Sign-on (SSO)
  • 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
  • Databases & Data Management
  • Heroku Postgres
  • Postgres Data Transfer & Preservation
  • Heroku Postgres Rollback

Heroku Postgres Rollback

English — 日本語に切り替える

Last updated January 25, 2021

Table of Contents

  • Creating a rollback database
  • Deprovisioning
  • Common use case: Recovery after critical data loss

Heroku Postgres rollback allows you to “roll back” the state of your database to a previous point in time, similar to how heroku releases:rollback allows you to roll back to an older deployment of your application.

Rollback does not affect your primary database, but instead follows the same pattern as fork: it provisions a new database that is not directly connected to the primary in any way. Like a fork, a rollback will take some time to become available.

The rollback period available varies by database plan.

If database credentials have been reset on the primary, rollback will continue to support going back to a point prior to credential reset. Once the fork has been created during the rollback process, a new set of credentials will be created.

Creating a rollback database

Before you roll back, you must ensure the desired rollback point is available for your database. Different database plans have different rollback availability. To check rollback availability for your current database, use the heroku pg:info command:

$ heroku pg:info --app sushi
=== HEROKU_POSTGRESQL_YELLOW_URL (DATABASE_URL)
Plan:        Standard 0
Status:      Available
Data Size:   584.6 MB
Tables:      29
PG Version:  9.2.4
Connections: 8
Fork/Follow: Available
Rollback:    from 2013-10-18 20:00 UTC
Created:     2013-04-18 20:14 UTC
Maintenance: not required

Rollback is not available on a new fork for a period after forking, nor on followers for a time after unfollowing.

Creating a rollback database uses the same mechanism as creating a follower: provisioning occurs on creation of a new database add-on with the --rollback flag. The --rollback flag can take the config var name of the database on the same app, an argument of the form appname::HEROKU_POSTGRESQL_COLOR, or the full URL of any Heroku Postgres database.

In addition, you must specify the time to roll back to. There are two ways to indicate the desired time: either an explicit timestamp, or a relative time interval. An explicit timestamp should be of the format 2013-10-22 12:34+00:00, including the time zone offset. You may also use a symbolic time zone. For example, 2013-10-22 12:34 US/Pacific. An interval should be of the format 3 days 7 hours 22 minutes. A recovery time must be passed with the --to flag, and a recovery interval with --by. At least one must be present, but not both. Rollback is not accurate down to the second. Seconds specified in the recovery time or interval are ignored.

A full rollback command looks like this:

$ heroku addons:create heroku-postgresql:standard-0 --rollback HEROKU_POSTGRESQL_YELLOW --to '2013-10-21 15:52+00' --app sushi

The target recovery time (and how long ago this is) will be echoed in the output of the provisioning command.

Preparing a rollback can take anywhere from several minutes to several hours, depending on the size of your dataset. The heroku pg:wait command shows the provisioning status of any new databases and can be used to determine when the rollback is up-to-date:

$ heroku pg:wait --app sushi
Waiting for database HEROKU_POSTGRESQL_SILVER_URL... available

Deprovisioning

When you are done with the rollback, deprovision it using heroku addons:destroy:

Be sure to remove the _URL suffix from the database name in this command.

$ heroku addons:destroy HEROKU_POSTGRESQL_YELLOW --app sushi
    !    WARNING: Destructive Action
    !    This command will affect the app: sushi
    !    To proceed, type "sushi" or re-run this command with --confirm sushi

Common use case: Recovery after critical data loss

Rollback is a great safety net in case of a critical data loss issue like accidentally dropping an important table. To recover the lost data through rollback:

  1. Create a rollback:

    $ heroku addons:create heroku-postgresql:standard-0 --rollback HEROKU_POSTGRESQL_YELLOW --to '2013-10-21 15:52+00' --app sushi
    Creating heroku-postgresql:standard-0 on ⬢ sushi... $50/month
    Database will become available after it completes rolling back
    to 2013-10-21 15:52+0000.
    Use `heroku pg:wait` to track status.
    postgresql-adjacent-88888 is being created in the background. The app will restart when complete...
    Use heroku addons:info postgresql-adjacent-88888 to check creation progress
    Use heroku addons:docs heroku-postgresql to view documentation
    
  2. Confirm that the rollback is up-to-date:

    $ heroku pg:wait --app sushi
    Waiting for database HEROKU_POSTGRESQL_SILVER... available
    
  3. Promote the rollback as the primary database

    $ heroku pg:promote HEROKU_POSTGRESQL_SILVER --app sushi
    
  4. Re-establish replication on all followers to the new leader (if applicable)

    $ heroku addons:create heroku-postgresql:standard-2 --follow HEROKU_POSTGRESQL_SILVER --app sushi
    Adding heroku-postgresql:standard-2 to sushi... done, v71 ($200/mo)
    Attached as HEROKU_POSTGRESQL_WHITE
    Follower will become available for read-only queries when up-to-date
    Use `heroku pg:wait` to track status
    

Keep reading

  • Postgres Data Transfer & Preservation

Feedback

Log in to submit feedback.

SQLite on Heroku Importing and Exporting Heroku Postgres Databases

Information & Support

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

Language Reference

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

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies