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
      • Node.js Behavior in Heroku
      • Working with Node.js
      • Troubleshooting Node.js Apps
    • 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 Postgres Advanced (Limited GA)
    • 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
  • Managing Heroku Postgres using the CLI

Managing Heroku Postgres using the CLI

English — 日本語に切り替える

Table of Contents [expand]

  • Postgres-Related CLI Commands
  • Postgres-Related CLI Plugins
  • data:pg:info and pg:info
  • data:pg:psql and pg:psql
  • pg:push and pg:pull
  • pg:ps, pg:kill, pg:killall
  • pg:promote
  • pg:reset

Last updated May 18, 2026

Heroku Postgres is integrated directly into the Heroku CLI and offers many helpful commands that simplify common database tasks.

You must be on Heroku CLI v11 or later to use the data:pg:* commands. Update the CLI version with heroku update.

Postgres-Related CLI Commands

Heroku Postgres Advanced is in limited general availability. To start creating and using Advanced databases, open a ticket with Heroku Support to request access. Subscribe to our changelog to stay informed of when Heroku Postgres Advanced is generally available.

There are different commands depending on the database tier. Use the data:pg:* commands on Advanced databases (Limited GA). Use the pg:* commands on Essential and classic Postgres databases.

Task Advanced Databases (Limited GA) Essential and Classic Databases See Also
Provision a Postgres database heroku data:pg:create heroku addons:create Provisioning Heroku Postgres Advanced

Provisioning Heroku Postgres
Destroy a Postgres database heroku data:pg:destroy heroku addons:destroy Provisioning Heroku Postgres Advanced

Provisioning Heroku Postgres
Get info on a Postgres database heroku data:pg:info heroku pg:info data:pg:info and pg:info
Open a psql session heroku data:pg:psql heroku pg:psql data:pg:psql and pg:psql
Promote a Postgres database to be the primary database heroku pg:promote heroku pg:promote pg:promote
Manage attachments on a Postgres database heroku data:pg:attachments
heroku data:pg:attachments:create
heroku data:pg:attachments:destroy
heroku addons:attach
heroku addons:detach
Provisioning Heroku Postgres Advanced

Provisioning Heroku Postgres
Blocks an operation until a Postgres database is available heroku data:pg:wait heroku pg:wait
Get info on Heroku Postgres plans and plan levels heroku data:pg:levels heroku addons:plans Provisioning Heroku Postgres Advanced
Capture and download database backups Not available heroku pg:backups Importing and Exporting Heroku Postgres Databases
Pull remote data from a Postgres database to your local machine Not available pg:pull pg:pull
Push data from a local database into a remote Postgres database Not available pg:push pg:push
Delete all content in a Postgres database Not available pg:reset pg:reset
Copy data from a source Postgres database to a target Postgres database Not available heroku pg:copy Upgrading the Version of a Heroku Postgres Database
View active queries with execution time in Postgres Not available pg:ps pg:ps, pg:kill, pg:killall
Terminate running queries in Postgres Not available pg:kill and pg:killall pg:ps, pg:kill, pg:killall
Run or view a diagnostics report on a Postgres database Not available heroku pg:diagnose Heroku Postgres Performance Analytics
Display queries with active locks on a Postgres database Not available heroku pg:locks Heroku Postgres Database Tuning
Show queries that have the longest execution time in a Postgres database Not available heroku pg:outliers Expensive Queries
Show dead rows and whether an automatic vacuum is expected on a Postgres database Not available heroku pg:vacuum-stats Managing VACUUM on Heroku Postgres
Show table and index bloat on a Postgres database Not available heroku pg:bloat Managing VACUUM on Heroku Postgres
Display queries holding locks on other queries waiting to be released on a Postgres database Not available heroku pg:blocking
Manage credentials on a Postgres database heroku data:pg:credentials
heroku data:pg:credentials:create
heroku data:pg:credentials:destroy
heroku data:pg:credentials:rotate
heroku data:pg:credentials:url
heroku pg:credentials
heroku pg:credentials:create
heroku pg:credentials:destroy
heroku pg:credentials:rotate
heroku pg:credentials:url
Heroku Postgres Credentials
Manage Postgres version upgrades on a database heroku data:pg:upgrade:run
heroku data:pg:upgrade:wait
heroku pg:upgrade:dryrun
heroku pg:upgrade:prepare
heroku pg:upgrade:run
heroku pg:upgrade:cancel
heroku pg:upgrade:wait
Upgrading the Version of a Heroku Postgres Database
Change the database configuration on Advanced databases and change database plans on non-Advanced databases heroku data:pg:update heroku addons:upgrade Manage Instance Pools on Heroku Postgres Advanced

Changing the Plan or Infrastructure of a Heroku Postgres Database
List and configure Postgres settings on your database heroku data:pg:settings heroku pg:settings Heroku PGSettings
Create a fork on a Postgres database heroku data:pg:fork heroku addons:create --fork Forking Your Heroku Postgres Database
Enable connection pooling on a Postgres database Not available heroku pg:connection-pooling:attach Server-Side Connection Pooling for Heroku Postgres
Manage Data Links on a Postgres database Not available heroku pg:links
heroku pg:links:create
heroku pg:links:destroy
Heroku Data Links
Manage maintenance events and windows on a Postgres database heroku data:maintenances
heroku data:maintenances:info
heroku data:maintenances:window
heroku data:maintenances:window:update
heroku data:maintenances:run
heroku data:maintenances:history
heroku data:maintenances
heroku data:maintenances:info
heroku data:maintenances:window
heroku data:maintenances:window:update
heroku data:maintenances:wait
heroku data:maintenances:schedule
heroku data:maintenances:run
heroku data:maintenances:history
Heroku Postgres Maintenance
Manage quotas on an Advanced database heroku data:pg:quotas
heroku data:pg:quotas:update
Not available Heroku Postgres Advanced Quotas

Postgres-Related CLI Plugins

  • Heroku mTLS Plugin CLI Commands
  • Heroku CLI Data Plugin for Heroku Streaming Data Connectors and Getting Started with Heroku Data Labs

data:pg:info and pg:info

To see all PostgreSQL databases provisioned by your application and the identifying characteristics of each, such as database size, status, number of tables, and PG version, use heroku data:pg:info for Advanced databases (Limited GA) and heroku pg:info for non-Advanced databases:

$ heroku pg:info -a example-app
=== DATABASE_URL, HEROKU_POSTGRESQL_RED

Plan:                  Standard 0
Status:                Available
Data Size:             320 MB / 64 GB (0.50%)
Tables:                39
PG Version:            16.9
Connections:           13/200
Connection Pooling:    Available
Credentials:           8
Fork/Follow:           Available
Rollback:              earliest from 2026-03-22 12:55 UTC
Created:               2024-08-26 09:52
Region:                eu
Data Encryption:       In Use
Continuous Protection: On
Enhanced Certificates: Off
Upgradable Extensions: Yes
Maintenance:           not required
Maintenance window:    Sundays 14:30 to 18:30 UTC
Add-on:                postgresql-octagonal-85179

=== HEROKU_POSTGRESQL_GRAY
Plan         Standard 2
Status       Available
Data Size    82.8 GB / 256 GB (32.34%)

To continuously monitor the status of your database, pass the command through the unix watch command:

$ watch heroku pg:info -a example-app

data:pg:psql and pg:psql

psql is the native PostgreSQL interactive terminal and is used to execute queries and issue commands to the connected database.

 

You must have PostgreSQL installed on your system to use heroku data:pg:psql and heroku pg:psql.

To establish a psql session with your remote database, use heroku data:pg:psql for Advanced databases (Limited GA) and the heroku pg:psql for non-Advanced databases:

$ heroku pg:psql -a example-app
--> Connecting to postgresql-octagonal-85179
psql (17.2 (Postgres.app), server 16.9 (Ubuntu 16.9-1.pgdg20.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.

example-app::RED=>

The command uses the database located at DATABASE_URL by default. If you have more than one database, specify the database you want to connect to as the first argument to the command. You can use the color as a shorthand:

$ heroku pg:psql gray
--> Connecting to postgresql-clean-71224
...

pg:push and pg:pull

pg:push and pg:pull aren’t supported on Heroku Postgres Advanced (Limited GA). Subscribe to our changelog to stay informed of when this feature is available for Advanced databases.

 

For a more in-depth guide on working with backups, read the import and export guide.

pg:pull

Use pg:pull to pull remote data from a Heroku Postgres database to a database on your local machine. This command creates a new local database named mylocaldb and then pulls data from the database at DATABASE_URL from the app example-app:

$ heroku pg:pull DATABASE_URL mylocaldb --app example-app

You can also specify the name of the database add-on to pull data from:

$ heroku pg:pull postgresql-animate-91581 mylocaldb --app example-app

To prevent accidental data overwrites and loss, the local database must not exist. Heroku prompts you to drop an existing local database before proceeding.

If providing a Postgres user or password for your local DB is necessary, use the appropriate environment variables. For example:

$ PGUSER=postgres PGPASSWORD=password heroku pg:push mylocaldb DATABASE_URL --app example-app

As with all pg:* commands, you can use shorthand database identifiers here. For example, to pull data from HEROKU_POSTGRESQL_RED on the app example-app, you could run heroku pg:pull example-app::RED mylocaldb.

pg:push

pg:push pushes data from a local database into a remote Heroku Postgres database. This command takes the local database mylocaldb and pushes it to the database at DATABASE_URL on the app example-app:

$ heroku pg:push mylocaldb DATABASE_URL --app example-app

You can also specify the name of the database add-on to push data to:

$ heroku pg:push postgresql-animate-91581 mylocaldb --app example-app

To prevent accidental data overwrites and loss, the remote database must be empty. Heroku prompts you to pg:reset a remote database that isn’t empty.

Usage of the PGUSER and PGPASSWORD for your local database is also supported for pg:push, just like for the pg:pull command. For example:

$ PGUSER=postgres PGPASSWORD=password heroku pg:push mylocaldb DATABASE_URL --app example-app

Troubleshooting

These commands rely on the pg_dump and pg_restore binaries that are included in a Postgres installation. It’s common, however, for the wrong binaries to be loaded in $PATH. Errors such as

!    createdb: could not connect to database postgres: could not connect to server: No such file or directory
!      Is the server running locally and accepting
!      connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
!
!    Unable to create new local database. Ensure your local Postgres is working and try again.

And

pg_dump: server version: 12.5; pg_dump version: 10.14
pg_dump: aborting because of server version mismatch
pg_dump: *** aborted because of error
pg_restore: [archiver] input file is too short (read 0, expected 5)

These errors are often a result of this incorrect $PATH problem. This problem is especially common with Postgres.app users, as the post-install step of adding /Applications/Postgres.app/Contents/MacOS/bin to $PATH is easy to forget.

pg:ps, pg:kill, pg:killall

pg:ps, pg:kill, and pg:killall aren’t supported on Heroku Postgres Advanced (Limited GA). Subscribe to our changelog to stay informed of when this feature is available for Advanced databases.

These commands give you view and control over currently running queries.

The pg:ps command queries the pg_stat_activity view in Postgres to give a concise view into currently running queries.

$ heroku pg:ps
 procpid |         source            |   running_for   | waiting |         query
---------+---------------------------+-----------------+---------+-----------------------
   31776 | psql                      | 00:19:08.017088 | f       | <IDLE> in transaction
   31912 | psql                      | 00:18:56.12178  | t       | select * from hello;
   32670 | Heroku Postgres Data Clip | 00:00:25.625609 | f       | BEGIN READ ONLY; select 'hi'
(3 rows)

You can then use the procpid column to cancel or terminate those running queries with pg:kill. Without any arguments, the command calls the pg_cancel_backend on the query and it attempts to cancel the query. If it fails, use the --force option to issue pg_terminate_backend to drop the entire connection for that query.

$ heroku pg:kill 31912
 pg_cancel_backend
-------------------
 t
(1 row)

$ heroku pg:kill --force 32670
 pg_terminate_backend
----------------------
 t
(1 row)

pg:killall is similar to pg:kill except it cancels or terminates every query on your database.

$ heroku pg:killall -a example-app
Terminating connections for all credentials... done

pg:promote

Promote a database to be the primary for your app with the heroku pg:promote command.

pg:promote updates the value of the DATABASE_URL config var with the newly promoted database’s connection string. It also creates an alternate attachment for the old primary database, assigned with a new HEROKU_POSTGRESQL_<color>_URL config var. The promotion process triggers a release and restarts the app.

$ heroku pg:promote HEROKU_POSTGRESQL_GRAY_URL -a example-app
Ensuring an alternate alias for existing DATABASE_URL... HEROKU_POSTGRESQL_PINK_URL
Promoting HEROKU_POSTGRESQL_GRAY_URL to DATABASE_URL... done

On classic databases, running pg:promote for a follower database doesn’t automatically make it unfollow its leader. Run pg:unfollow on followers to stop replication before promoting it.

 

After a promotion, the demoted database still exists and incurs charges. Delete your old primary database with heroku addons:destroy HEROKU_POSTGRESQL_COLOR.

Promotions When Using Connection Pooling

If your old primary used Connection Pooling attached with the default name DATABASE_CONNECTION_POOL, pg:promote reattaches the connection pooler to the new primary.

If you use Connection Pooling attachments under non-default names, you must update them after running pg:promote. Activate Connection Pooling on your new primary to repoint the connection pooling URL:

$ heroku pg:connection-pooling:attach DATABASE_URL --as MY_DATABASE_CONNECTION_POOL -a example-app
Enabling Connection Pooling on postgresql-octagonal-85179 to example-app... done
Setting MY_DATABASE_CONNECTION_POOL config vars and restarting example-app... done, v853

pg:reset

pg:reset isn’t supported on Heroku Postgres Advanced (Limited GA). Subscribe to our changelog to stay informed of when this feature is available for Advanced databases.

The PostgreSQL user your database is assigned doesn’t have permission to create or drop databases. To delete all the content in your database use pg:reset.

$ heroku pg:reset DATABASE
 ›   Warning: Destructive action
 ›   postgresql-fitted-17726 will lose all of its data
 ›

To proceed, type example-app or re-run this command with --confirm example-app: example-app
Resetting postgresql-fitted-17726... done

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