3

I´m having some trouble sharing a postgres database between my two Heroku apps.

I want the database of App A to be shared with App B, so I attached the App A postgres to App B, then I deleted App B´s original database.

However, trying to connect to from App B to the database results in this message:

PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I have tried to restart the dynos and such but still no luck. Does anyone have any ideas on how to solve this?

MZaragoza
  • 10,108
  • 9
  • 71
  • 116
marsrover
  • 715
  • 11
  • 27
  • Check this link [Stackoverflow](http://stackoverflow.com/questions/5981508/share-database-between-2-apps-in-heroku). It might helps you. – Pulkit Agarwal Jan 31 '16 at 15:04

1 Answers1

1

All you have to do is set the DATABASE_URL config var for app_a and app_b to the same value. First, get the DATABASE_URL for your app_a:

$ heroku config | grep DATABASE_URL  --app app_name_a DATABASE_URL => postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx

Then, set the DATABASE_URL for app_b to this value:

$ heroku config:add DATABASE_URL=postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx --app app_name_b
Adding config vars: DATABASE_URL => postgres://xxxxxx:xxxxxxxxxxxx@ec2-000-000-00-00.compute1.amazonaws.com/xxxx Restarting app... done, v99. 

That's it

I hope that this helps

MZaragoza
  • 10,108
  • 9
  • 71
  • 116