Yujun Wu
Yujun Wu

Reputation: 3012

ERROR Unkown database: DATABASE_URL after overriding the DATABASE_URL in the heroku app

I am trying to connect two Heroku apps to one database. So I overrided the DATABASE_URL. now the heroku config as:

=== muse-me Config Vars
DATABASE_URL:                postgres://rbbcoxizviewiu:taJsBZf...
GEM_PATH:                    vendor/bundle/ruby/1.9.1
HEROKU_POSTGRESQL_OLIVE_URL: postgres://jnlltenwyvmdup:Q5Doaw...
LANG:                        en_US.UTF-8
PATH:                        bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV:                    production
RAILS_ENV:                   production

Then I run

heroku pg:psql DATABASE_URL

It gave me an error:

!    Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_OLIVE_URL

What should I do? Do I really connect to the database with the DATABASE_URL?

Thanks

Upvotes: 2

Views: 2399

Answers (2)

Jonathan K
Jonathan K

Reputation: 651

"DATABASE_URL" is just a placeholder for "HEROKU_POSTGRESQL_OLIVE_URL". If you run:

heroku pg:psql HEROKU_POSTGRESQL_OLIVE_URL

That should work because you're explicitly telling pg which database url to use. To be able to use that command without specifying the db, you need to promote it to be your primary db:

heroku pg:promote HEROKU_POSTGRESQL_OLIVE_URL
heroku pg:psql

More info on promote is located here: https://devcenter.heroku.com/articles/heroku-postgresql#pgpromote

Upvotes: 3

pjam
pjam

Reputation: 6356

When running

heroku pg:psql DATABASE_URL

heroku tries to connect to the URL : DATABASE_URL, which obviously doesn't exist, it does read the ENV var DATABASE_URL

So if you're in the folder of your app, simply running

heroku pg:psql

is enough, otherwise, you can specify the app

heroku pg:psql --app <YOUR_APP>

And then heroku will read the DATABASE_URL var from the app it's connecting on.

Upvotes: -1

Related Questions