piggybacking on this post: Can't connect AWS RDS using sequelize
I am experiencing the same error, but am thoroughly confused over what's happening.
the following connection with pg works
const pg = require('pg')
// ...
async function pgExample () {
try {
const client = new pg.Client({
host: DB_HOST,
port: DB_PORT,
user: DB_USER,
password: DB_PASS,
database: DB_NAME,
ssl: {
rejectUnauthorized: false
}
})
await client.connect()
const res = await client.query("SELECT $1::text as connected", [
"Connection to postgres successful!",
])
console.log(res.rows[0].connected)
await client.end()
} catch (error) {
console.error("Error occurred:", error)
}
}
pgExample()
// this works
but the following sequelize code does not work
const { Sequelize } = require('sequelize')
// ...
async function sequelizeExample () {
try {
const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
host: DB_HOST,
port: DB_PORT,
database: DB_NAME,
dialect: 'postgres',
dialectOptions: {
ssl: {
rejectUnauthorized: false
}
}
})
await sequelize.sync()
console.log('Connection to postgres successful!')
} catch (error) {
console.error("Error occurred:", error)
}
}
sequelizeExample()
// this breaks
I have also tried alternative configurations, like
const URI = `postgres://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}`
const sequelize = new Sequelize(URI, {
database: DB_NAME,
dialect: 'postgres',
dialectOptions: {
ssl: {
rejectUnauthorized: false
}
}
})
the error:
Error occurred: ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "##.###.##.###", user "####", database "####", no encryption
at Client._connectionCallback (/Users/aronlilland/Downloads/example/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:145:24)
at Client._handleErrorWhileConnecting (/Users/aronlilland/Downloads/example/node_modules/pg/lib/client.js:327:19)
at Client._handleErrorMessage (/Users/aronlilland/Downloads/example/node_modules/pg/lib/client.js:347:19)
at Connection.emit (node:events:513:28)
at /Users/aronlilland/Downloads/example/node_modules/pg/lib/connection.js:117:12
at Parser.parse (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket.<anonymous> (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9) {
parent: error: no pg_hba.conf entry for host "##.###.##.###", user "####", database "####", no encryption
at Parser.parseErrorMessage (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 160,
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: '542',
routine: 'ClientAuthentication'
},
original: error: no pg_hba.conf entry for host "##.###.##.###", user "####", database "####", no encryption
at Parser.parseErrorMessage (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/aronlilland/Downloads/example/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 160,
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: '542',
routine: 'ClientAuthentication'
}
}