Cannot connect to remote Heroku Postgres database using Play Framework 2.2.2

坚强是说给别人听的谎言 提交于 2019-12-11 02:42:14

问题


I have an Heroku account and i created an app and an Heroku-Postgres database. I already commited the app to the Heroku cloud, but i cannot access to the DB that i created.

I'm using play, and when i connect my project in my local DB, the application.conf configurations are:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/postgres"
db.default.user=postgres
db.default.password=password

And run my server locally and it works fine.

Before i upload my app to Heroku i changed this file to access my Heroku-Postgres DB:

db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://url:5432/database_name?user=name&password=pass&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"

The user and password fields are no longer needed. I've already created a file in the root of my project named "Procfile" that has:

web: target/universal/stage/bin/playsense -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}

I discovered this on the documentation. I don't understand why it doesn't connect to my DB. I used pgAdminIII with the DB credentials and it works fine.

It's something missing/wrong and i don't know what.

Can someone help me? Thanks in advance!


回答1:


You probably need to unset the db.default.user and db.default.password config params when running on Heroku. But I'm not sure of an easy way to do that. So what I usually do is to not set them in the conf/application.conf and instead I do something like:

db.default.driver=org.postgresql.Driver
db.default.url="postgres://postgres:password@localhost:5432/postgres"
db.default.url=${?DATABASE_URL}
#db.default.user=postgres
#db.default.password=password

That provides a default db.default.url but overrides it with the DATABASE_URL env var if it is set.



来源:https://stackoverflow.com/questions/22712611/cannot-connect-to-remote-heroku-postgres-database-using-play-framework-2-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!