By kathirva
I am trying to access my managed postgreSQL database from my node.js app which is hosted in Google Cloud. I am getting the above error. I am using pg-promise in my node.js app. How to go about it? Please advise.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello, I believe that you are getting a deny on the connection as the client is not in the pg-hba-conf file, there should be a way to authorize networks/ or a similar thing on from your database provider.
You need to whitelist the IP you are making the request from in /etc/postgresql/9.5/main/pg_hba.conf (be 9.5 the version of you postgresql installation). An example:
host all all 1.2.3.4/32 md5
Where md5 is the trust method, 32 the network mask and 1.2.3.4 the request IP
I am using a Digital Ocean database and while I am not sure what it means, I was able to get around this by using either of two techniques: either disable rejectUnauthorized in ssl, or generate a self-signed certificate (public and private key) and download the CA Certificate from the database and pass those to ssl.
const pool = new Pool({
host: process.env.PGHOST,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
port: process.env.PGPORT,
ssl: {
rejectUnauthorized: false
}
});
I am not sure if either of these is an incorrect solution even though it allowed me to connect and do queries.
https://node-postgres.com/features/ssl https://stackoverflow.com/questions/31861109/tls-what-exactly-does-rejectunauthorized-mean-for-me
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.