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