Skip to content
Latchkey

heroku config:set and pg: App Config and Postgres

heroku config:set writes config vars (env) for an app, and heroku pg inspects the attached Heroku Postgres database.

Config vars are how Heroku injects environment into dynos, and pg is the database toolbox. Both are common in a deploy pipeline.

What it does

heroku config:set KEY=value sets config vars and restarts the dyno; heroku config:get reads one. heroku pg:info shows the database, heroku pg:psql opens a psql session, and heroku run runs a one-off command (such as a migration) in a fresh dyno with the app's config.

Common usage

Terminal
heroku config:set NODE_ENV=production API_URL=https://api.example.com --app my-app
heroku pg:info --app my-app
# run a one-off migration in a dyno
heroku run --app my-app -- npm run migrate

Options

Command / flagWhat it does
config:set K=VSet config vars (restarts the app)
config:get KRead a single config var
pg:infoShow Postgres status and metrics
pg:psqlOpen a psql session to the database
run -- <cmd>Run a one-off command in a dyno
--app <name>Target app

In CI

Set HEROKU_API_KEY for non-interactive auth. For migrations prefer heroku run -- <cmd> with the -- separator so flags pass through; it runs the command and exits rather than opening a shell. config:set restarts the app, so batch related vars into one call.

Common errors in CI

"Invalid credentials provided" means HEROKU_API_KEY is missing or wrong. "Couldn't find that app" means a bad --app. heroku run in CI sometimes warns "Running ... up, run.1 (Free): ..." and needs --type or a non-interactive terminal; the command still executes and its exit code gates the step.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →