Deploying a PostgreSQL database with HEROKU and getting SSL off error
February 18, 2021
I'm currently working on building a postgres database for a new project and wanted to get what I have so far deployed on Heroku. Something has changed since I've last deployed a database(db) project on Heroku, which was only 2 months ago!
When I tried to seed my data on Heroku after doing a git push, I kept getting this error in my terminal "UnhandledPromiseRejectionWarning: error: no pg_hba.conf entry for host"..."SSL off". This was an error that I've never encountered before.
After a quick Google, I found that someone also had the same issue on stack overflow. It's definitely related to ssl. See more on the stack overflow link. Since I am working with node, I've found the Heroku documentation regarding this and it was very thorough. See Heroku's main resource on postgres ssl issue: https://devcenter.heroku.com/articles/heroku-postgresql#heroku-postgres-ssl.
If you're also working on a postgres database with node. Here's the exact thing I had to model after below:
When I tried to seed my data on Heroku after doing a git push, I kept getting this error in my terminal "UnhandledPromiseRejectionWarning: error: no pg_hba.conf entry for host"..."SSL off". This was an error that I've never encountered before.
After a quick Google, I found that someone also had the same issue on stack overflow. It's definitely related to ssl. See more on the stack overflow link. Since I am working with node, I've found the Heroku documentation regarding this and it was very thorough. See Heroku's main resource on postgres ssl issue: https://devcenter.heroku.com/articles/heroku-postgresql#heroku-postgres-ssl.
If you're also working on a postgres database with node. Here's the exact thing I had to model after below:
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
client.connect();
Note that this is the code you will need to deploy with for Heroku only. For development, make sure the connection string is set locally. It will cause errors when you use the model code above for developing but don't worry, use the snippet for Heroku deployment.
The key thing is for deployment, you need to add the ssl: {rejectUnauthorized: false} for Heroku.
After I've deployed on Heroku, I ran my seed data and saw that my seed data was successfully shown on my deployed link. I commented out the model snippet and then, just have my connection string to my localhost again while I'm developing. I hope this helps you!
Posted by Ninja Space Content. Posted In : postgres