Reputation: 518
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 !
Upvotes: 3
Views: 616
Reputation: 518
What I did is to set the DB credentials as environment variables in Heroku, and use them inside a config object like so:
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.
Upvotes: 1
Reputation: 1590
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
.
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
Upvotes: 1