I want to connect to postgres in Aws server. I have installed "pg" to node.
I have tried to use the connection String, but there is no way to add private key there. So I also try with
const pool = new Pool({
user: 'dbuser',
host: 'database.server.com',
database: 'mydb',
password: 'secretpassword',
port: 3211,
privateKey : require('fs').readFileSync('./ssh_keys/my_key')
})
In both cases I get connection refused.
Related
I'm playing with Heroku / DigitalOcean ("DO") App hosting services, trying to simply connect my NodeJS app to a Heroku/DO database. These services populate my environment variables with the following:
DATABASE_URL="postgresql://username:password#url:ip/dbname?sslmode=require"
Unfortunately, when I'm running Sequelize, I get the following error message:
ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "[my ip address]", user "[db user]", database "[db name]", SSL off
I think the connection string might be misconfigured as I can clearly see it's trying to connect over ssl.
$ node -v
v15.9.0
Hi i share my connection with Digital Ocean DB PostgreSQL cluster
production: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_DATABASE,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}
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.
I have node server on which i used mysql module as shown below
const db = mysql.createConnection({
host:'localhost',
user: 'root',
password: '',
database: 'test'
});
db.connect(function(err){
if (err) console.log('Errors', err)
console.log('connenected');
})
when i replace ip address of remote database or ip address of my local machine on which xammp is running instead of localhost it fails somehow i tried to find out solution some says i need to use port in connection but it fails. Thanks in advance
Step1: Allow database to connect remote IP by given this SQL.
GRANT ALL PRIVILEGES ON *.* TO 'root'#'ipaddressofyourpc' IDENTIFIED BY 'password' WITH GRANT OPTION;
Step2: Flush the PRIVILEGES
FLUSH PRIVILEGES;
Step3:
var mysql = require('mysql');
var connection = mysql.createPool({
connectionLimit: 100,
host:'ipaddressofremotedb',
user:'usernameofdb',
password:'password',
database:'dbname',
port: 3306,
debug: false,
multipleStatements: true
});
I am running NodeJS microservice that talks to Postgres database. But when I am trying to start the service I am getting below error. I do not have any idea why this error is popping up.
Error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection(rejection id:1): error: database “root” does not exist
My DB connection details:
const pg = require(“pg”);
const client = new pg.Client({
host: “txslmxxxda6z”,
user: “mom”,
password: “mom”,
db: “mom”,
port: 5025
});
I am able to resolve this myself. The issue is in connection config. It should be database but not db so this was causing the issue. PFB answer
const client = new pg.Client({
host: “txslmoxxx6z”,
user: “mom”,
password: “mom”,
//change db to database
database: “mom”,
port: 5025
});
I'm playing around on Heroku and trying to link to a postgres DB. My app is linked directly to the github source code. When I run it locally with the Heroku DB credentials and with npm start it works, but not when it is deployed, I've got this error:
{"name":"SequelizeConnectionError","message":"password authentication failed for user \"riunhwzbjuwwgw\"","parent":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"},"original":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"}}
Any ideas at all?
Edit : here's the connection
var sequelize = new Sequelize(config.db.dbName, config.db.username, config.db.password, {
host: config.db.host,
dialect: config.db.dialect,
port: config.db.port,
dialectOptions: {
ssl: true
},
logging : false
});
and my variables
db: {
dbName: process.env.DBNAME,
username : process.env.DBUSER,
password : process.env.DBPASSWORD,
host : process.env.DBHOST,
dialect: "postgres",
port : 5432
}
Like I said, it works locally. The password is set like the DBUSER riunhwzbjuwwgw, could it be something those slashes? \"riunhwzbjuwwgw\"