Reputation: 11
I have got an issue when trying to connect Azure postgres database from Nodejs app. Connecting by sequelize and pg lib give me same issue "no pg_hba.conf entry for host". After looking around for a while, I found solution for both libs from many sources. The root cause is that Azure db requires SSL connection by default, turning it off can resolve the issue but it's not secure. Adding ssl support from app is better choice.
With pg:
const { Client } = require('pg');
let client = new Client({
connectionString: process.env.DB_URI + '/postgres',
ssl: true,
});
With sequelize, dialect option must be specified
export const sequelize = new Sequelize(process.env.DB_URI + '/postgres', {
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true
}
},
});
Upvotes: 0
Views: 353
Reputation: 8402
Nodejs - Can't connect to Azure database with sequelize and pg - no pg_hba.conf entry for host.
The cause of issue is Azure database for PostgreSQL has SSL enable by default. and the databaseConnectionUri
method not considering the SSL configuration value when constructing the URI passed to the pg module. The pg module checks for an SSL key with a value of either true or 1 in the query string of the URI.
To solve this, the solution can be disable require_secure_transport
server parameter to OFF .
If don't want to disable SSL, you can ADD SSL check in the connection string as below:
ssl : true
Also see this similar SO Thread answers
Upvotes: 1