0

I can't manage to share two PostgreSQL heroku dbases between two heroku apps.

Doesn't work

What I've tried so far (I'm using the Heroku CLI):

$ heroku config:set DATABASE_URL=`heroku config:get DATABASE_URL -a my-heroku-app-original`
Setting config vars and restarting my-heroku-app... done, v20
DATABASE_URL: postgres://...correct url...

$ heroku config
=== msite-poniai Config Vars
DATABASE_URL:                 postgres://...correct url...

When I try to access psql, depending on whether I've added a new db or not, I get these two answer (I both cases heroku doesn't see the DATABASE_URL I've just provided.

$ heroku pg:psql
 !    Your app has no databases.
$ heroku pg:psql
 !    Unknown database. Valid options are: HEROKU_POSTGRESQL_NEWLYADDED_URL

Works

If I provide psql with the exact location of the db (in this case the original app that has the db as an add-on) it does manage to connect.

$ heroku pg:psql HEROKU_POSTGRESQL_ORIGINAL_URL --app my-heroku-app-original
psql (9.1.9)

I've read

I've closely followed advice given in Share database between 2 apps in Heroku and heroku-postgresql#create-new-db.

Community
  • 1
  • 1
Morgan Wilde
  • 16,795
  • 10
  • 53
  • 99

1 Answers1

1

Simply copying a config var from one app to another does not attach the referenced database to the app. Were the host or password to change on the first, your second app would be broken. There is a highly alpha plugin you can try https://github.com/heroku/heroku-attachable-resources but it does some weird things like no longer give default names to databases, and overwrites DATABASE_URL if you don't pass in --config and sometimes doesn't let you remove databases.

Will
  • 2,921
  • 16
  • 12
  • this is certainly helpful, even though it doesn't fix my issue while staying inside default heroku environment. – Morgan Wilde Apr 17 '13 at 07:53
  • How does attachable-resources *not* fix your issue? – catsby Apr 17 '13 at 14:13
  • @ctshryock because I feel there has to be a solution within the Heroku sandbox. From what I'm reading, unless I'm missing something, this is exactly the promised functionality. Even though I can't manage to get it working... – Morgan Wilde Apr 17 '13 at 18:12
  • `pg:psql` tries to connect to a database that app owns. In your example, when you set `DATABASE_URL` manually, that doesn't mean the app owns it. The API may have changed here. Why not `pg:psql -a original_app` ? – catsby Apr 17 '13 at 22:08
  • 1
    furthermore, ctshryock and I work on heroku postgres, so this sorta is as authoritative an answer there'll be until/if attachable resources is released and something written in devcenter.heroku.com – Will Apr 18 '13 at 06:25
  • I'm sorry for taking my time in figuring out what I think is best. I do feel that it would be wonderful to have a `pg:attach DB_URL --app original_app`, but at the end of the day, this is such a minor detail. The service is perfect and I'm a very happy user :) and to have two people working on it assist you, well that's just awesome, please keep it up! – Morgan Wilde Apr 18 '13 at 08:03
  • 1
    yeah the user experience around the current attachable resources is bad, which is why it's still alpha and not part of the main CLI. Thanks for the feedback on what you think an intuitive command would be. I'm not sure what it'll end up being, but that data point helps. – Will Apr 20 '13 at 20:01