3

I have an app on Heroku which is already running 5 months.

Suddenly I saw today that the server is crashed with this error message:

no pg_hba.conf entry for host "", user "", database "", SSL off

I don't understand what went wrong cause it's worked fine yesterday and I didn't released a new version by two weeks.

I also tried to connect to the db from my local machine and it's worked properly.

I'll appreciate any help !

Guy Ben David
  • 478
  • 3
  • 15

2 Answers2

1

I had the same issue. My app runs 24/7, and at March 13th, 2021 around 1PM GMT-0600 your issue started occuring. My app could no longer connect to a Database.

The following 3 steps solved the issue (for me):

Add this environment variable in Heroku under config vars:NODE_TLS_REJECT_UNAUTHORIZED=0.

E.G:
enter image description here

Make sure you have SSL rejectUnauthorized to false

E.G (in Node.js):

const client = new Client({connectionString: databaseConnectionString, ssl: { rejectUnauthorized: false }});
await client.connect();

Add this to the database connection string, Not to the actual environment variable: ?sslmode=require

E.G: (In Node.js)

const databaseConnectionString= process.env.DATABASE_URL + "?sslmode=require";
new Client({connectionString: databaseConnectionString ... });

Reference 1, heroku says SSL must be used in production & add sslmode=require programatically

Reference 2, after doing the above I was getting 'error self signed certificate', stackoverflow post helped solve the issue by adding the environment variable

dustytrash
  • 1,568
  • 1
  • 10
  • 17
1

What I did is to set the DB credentials as environment variables in Heroku, and use them inside a config object like so:

enter image description here

I preferred to connect using the connection string because it's much more cleaner, but it's seems like this option is not working anymore.

Guy Ben David
  • 478
  • 3
  • 15
  • 1
    Note that the credentials change overtime: https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku You should use the credential String heroku provides if you're using Heroku's database – dustytrash Mar 16 '21 at 16:02