0

I am using Digitalocean managed PostgreSQL and trying to access the database from node.js (using pg-promise) which is a Google Cloud Function.

no pg_hba.conf entry for host "IP-ADDRESS", user "username", database "database", SSL off

Below is my db config

import * as pgPromise from 'pg-promise';
const dbConfig = {
    username: 'username',
    password: 'password',
    host: 'host string',
    port: PORTNUMBER,
    database: 'database',
    sslmode: 'require'
};
const pgp = pgPromise({});
const db = pgp(dbConfig);
export { db, pgp };

How to fix this? Please advise.

Giri
  • 451
  • 1
  • 4
  • 13
  • Hello, I believe that you are getting a deny on the connection as the client is not in the [pg-hba-conf](https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html) file, there should be a way to authorize networks/ or a similar thing on from your database provider. – Luis Manuel Aug 06 '20 at 17:07
  • 1
    The problem that I'm thinking about now, is that cloud functions can't have a static ip that you could authorize (I believe it is dynamic), so you need a work around for this, maybe a [proxy](https://stackoverflow.com/questions/38811882/possible-to-get-static-ip-address-for-google-cloud-functions#:~:text=It's%20not%20possible%20to%20assign,to%20achieve%20a%20similar%20effect.)? – Luis Manuel Aug 06 '20 at 17:08
  • 1
    What @LuisManuel already said, plus there is no `sslmode` parameter within `pg-promise`, there is only `ssl`, [see in declarations here](https://github.com/vitaly-t/pg-promise/blob/master/typescript/pg-subset.d.ts#L79). – vitaly-t Aug 06 '20 at 17:52
  • Thank you guys for helping out in resolving this. I just removed the restricted access to the db in DO Postgres and also removed sslmode, instead I added ssl in the connection parameters. It worked. Though I would need to have restricted access in the future. So I will try to add proxy as per @LuisManuel. – Giri Aug 07 '20 at 14:16

0 Answers0