40

This is the command I have to find the name of a heroku database:

$ heroku config | grep POSTGRESQL

I get a result similar to:

HEROKU_POSTGRESQL_NAVY_URL: postgres://wxjwilh:[email protected]:52/d14grmkt

which part of this output is the database name I can use with the command:

$ heroku pg:reset <DATABASE>

I tried using the whole url but got an invalid argument error.

6 Answers 6

59

hope everyone confuses with placeholder and constant.

Assume having a db with name d6u5qhrlnbdfmp. then it is NOT necessary to type

heroku pg:reset d6u5qhrlnbdfmp

Instead we can plainly type

heroku pg:reset DATABASE_URL

the sample output

E:\git\stutzen>heroku pg:reset d6u5qhrlnbdfmp --app stutzen
 !    Unknown database: d6u5qhrlnbdfmp. Valid options are: DATABASE_URL, HEROKU_
POSTGRESQL_CYAN_URL

E:\git\stutzen>heroku pg:reset DATABASE_URL --app stutzen

 !    WARNING: Destructive Action
 !    This command will affect the app: stutzen
 !    To proceed, type "stutzen" or re-run this command with --confirm stutzen


> stutzen
Resetting HEROKU_POSTGRESQL_CYAN_URL (DATABASE_URL)... done
Sign up to request clarification or add additional context in comments.

1 Comment

all heroku pg:* commands (including those in pg-extras can use any of the following as a DB indicator: HEROKU_POSTGRESQL_NAVY_URL, HEROKU_POSTGRESQL_NAVY, NAVY. In case NAVY is also your primary DATABASE_URL, you can use that too.
23

URL consists of the following parts:

scheme://username:password@host:port/database

So, in your case DB name is d14grmkt.

Comments

14

I had a hard time to reset my database on Heroku. I post this, because I think it's the most straightforward solution. To find out the database name cd to your application folder and type:

heroku pg:info

Output will be something like

=== HEROKU_POSTGRESQL_BRONZE_URL
#other stuff

To reset the database type:

heroku pg:reset HEROKU_POSTGRESQL_BRONZE_URL

you have to confirm with your application name.

1 Comment

Came here from googling trying to find something like heroku pg:info to list my database name. Great answer, thank you!
8

While using the command:

$ heroku pg:reset DATABASE

It will tell you the available database name like this:

! Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_COPPER_URL, SHARED_DATABASE

so try the options it gave like this

$ heroku pg:reset HEROKU_POSTGRESQL_COPPER_URL

Comments

2

Late to the party, but if you need the db name, for example to add it as an addon to another instance, you run

heroku addons

In the list you will see your postgres addon, in the 'Add-on' column is the name of the db app that is attached

Comments

0

NOT MENTIONED IN THE HEROKU WEBSITE DOCUMENTATION:

 heroku addons:create heroku-postgresql:hobby-dev --version=12 --app "APPNAME" --name "APPNAME-database"

--app : Specify the heroku app you want to add the database too. Really good if you have more than one heroku app.

--name : The name you would like to give your database. I like to take my application name and postfix it with "database" as a nice convention. Better than whatever randomly generated name you'll get.

APPNAME: A placeholder for whatever your application name is.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.