typeorm: Unable to connect to Heroku postgres from outside of Heroku
In order to connect to Heroku postgres from outside of Heroku we need to use SSL.
So, I’m getting the following message when trying to connect typeorm to the Heroku postgres.
"message": "no pg_hba.conf entry for host "xxx", user "xxx", database "xxx", SSL off"
I believe this is happening because the postgres driver is trying to connect without SSL. If I’m correct, how can I tell the sql driver to use SSL.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 19
- Comments: 25 (4 by maintainers)
Links to this issue
Commits related to this issue
- Add ssl for DOAP When running migrations on DOAP I got the following error: Error during migration run: error: no pg_hba.conf entry for host "134.209.211.49", user "db", database "db", SSL off. Thi... — committed to ardentink/adr-api by dansteren 4 years ago
- Update to fix the issue, this github issue explains the issue https://github.com/typeorm/typeorm/issues/278 — committed to andreGarvin/openkey by andreGarvin 3 years ago
@idudinov
I’ve just run into this issue and it seems that
node-postgreshave added an option to disable rejecting unauthorized connections. I don’t think this is safe to run in production though. I’m just using it to run my migrations.I believe the ideal solution is to get a new SSL certificate, but for now I have:
Solution is here. To do so in typeorm you need to provide option in special “extra” section of connection options:
What fixed for me while using Postgres from Heroku was only adding the following environment variable:
hi there! still don’t able to connect to remote Heroku Postgres server from local machine, my config looks like:
also tried to set up
PGSSLMODE=requireas env var.TypeORM in package.json:
"typeorm": "0.2.20"getting the error:
not sure what certificate should I use, or can I bypass it somehow?
thanks in advance!
Also PGSSLMODE=require solves this problem.
You need to set
it works for me. Thanks!
What worked for me:
thanks a lot it worked for me too i was using typeorm and nest.js and i was getting this error while connecting a database located in digitalocean
In my case:
put what you get from
heroku config:get DATABASE_URLto your.envfile (heroku will automatically add that toprocess.envconnect with:
Just as a follow up, since Heroku enforced SSL for all postgres connections the above is the solution they recommend.
So I guess it is safe for production. 😊
For me it worked with:
jeez it fails on Heroku as well!
UPDATE: sorry, false alarm! it’s actually
node-postgresissue: https://github.com/brianc/node-postgres/issues/2009worked for me too.