My Heroku app crash a week ago and I have been troubleshooting for 3 days with no success. Tried to change the connection code to ssl and also did some changes to pg_hba.conf
and postgresql.conf
files but no luck.
This is the error that keep coming up :
ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "", user "", database "", SSL off
at /app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:182:24
at Connection.connectingErrorHandler (/app/node_modules/pg/lib/client.js:194:14)
at Connection.emit (events.js:210:5)
at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:134:12)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:308:12)
at readableAddChunk (_stream_readable.js:289:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
name: 'SequelizeConnectionError',
parent: error: no pg_hba.conf entry for host "52.206.229.39", user "pirotuslftnuae", database "d7q6mo0trncmiq", SSL off
at Connection.parseE (/app/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/app/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:308:12)
at readableAddChunk (_stream_readable.js:289:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
name: 'error',
length: 167,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '496',
routine: 'ClientAuthentication'
},
const db = new Sequelize({
user: "name",
password: "****",
database: "databaseName",
port: 5432,
host: "localhost",
ssl: true,
dialect: 'postgres',
dialectOptions: {
"ssl": {"rejectUnauthorized": false}
}
});
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow rep
# - Connection Settings -
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_director`enter code here`ie
I finally solve my issue with this ssl code in my database file
let config
if (process.env.DATABASE_URL) {
config = {
logging: false,
ssl: true,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}
} else {
config = {
logging: false
}
}
const db = new Sequelize(
process.env.DATABASE_URL ||
`postgres://localhost:5432/${databaseName}`,
config
)