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\"
Related
I have this NodeJS API hosted on App Engine and a MySQL instance on Cloud SQL
I'm using mysql2 and dotenv packages for my connection and for environment variables access, here's how I create the connection:
import mysql from "mysql2";
import * as dotenv from "dotenv";
dotenv.config();
export const db =
process.env.NODE_ENV === "development"
? mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
})
: mysql.createConnection({
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
socketPath: `/cloudsql/${process.env.DB_INSTANCE_NAME}`,
});
I get to this connection creation by reading the official documentation of GCP, when I run it locally it works just fine, but when I deploy the app to App Engine I'm receiving this error:
Error: getaddrinfo ENOTFOUND 172.17.0.1:3306
I think that ip and port are the defaults for the proxy connection or something like that because I'm not setting that ip on any variable
Here's how I set the environment variables on app.yaml
runtime: nodejs14
env: standard
instance_class: F1
automatic_scaling:
min_idle_instances: 1
max_idle_instances: automatic
min_pending_latency: automatic
max_pending_latency: automatic
env_variables:
DB_USER: <db-user>
DB_PASS: <db-pass>
DB_NAME: <db-name>
NODE_ENV: production
DB_INSTANCE_NAME: <db-instance-name>
beta_settings:
cloud_sql_instances: <db-instance-name>
I've already check that the service user has the right permissions and roles
I don't know if I'm missing some configuration or if my app.yaml need another thing
I have tried to add the ip host directly in the connection creation but I'm getting the same behavior
export const db =
process.env.NODE_ENV === "development"
? mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
})
: mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
socketPath: `/cloudsql/${process.env.DB_INSTANCE_NAME}`,
});
I have been fighting with this issue for three days, so any help will be very appreciated for me
Thanks in advance.
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 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.
If you use sequelize as your ORM with postgres database, you may see this error code, especially for first-timer, including me. Found out the problem from this discussion .
Just define the 'port' property with 5432 (default postgres port) will fix the problem.
var orm = new sequelize('database', 'user', 'password', {
dialect: 'postgres',
host: 'localhost',
port: '5432' /* define database port */
});
i am using GeddyJs with a heroku cedar app deployment. I am using Heroku Postgres services for the database.
I have configured the username/password/hostname/dbname in the config file on geddyjs but when i go to run node app.js it throws an error for no pg_hba.conf i know this related to SSL not being used while accessing the db remotely but i have no clue how to force SSL on the connection..
Here is the error log:
error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off
at p.parseE (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:503:11)
at p.parseMessage (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:363:17)
at Socket.p.attachListeners (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:86:20)
at Socket.EventEmitter.emit (events.js:96:17)
at TCP.onread (net.js:397:14)
[Tue, 05 Mar 2013 22:39:49 GMT] ERROR Worker 843 died.
my config/development.js file:
var config = {
detailedErrors: true
, debug: true
, hostname: 'localhost'
, port: 3000
, model: {
defaultAdapter: 'postgres'
}
, db: {
postgres: {
port: 5432
, password: 'foobar'
, database: 'database1'
, host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
, user: '12345'
}
}
, sessions: {
store: 'memory'
, key: 'sid'
, expiry: 14 * 24 * 60 * 60
}
};
module.exports = config;
You need to add ssl: true to your postgres config.
postgres: {
port: 5432
, password: 'foobar'
, database: 'database1'
, host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
, user: '12345'
, ssl: true
}
Geddy simply passes this config object to the pg module. Check the pg.client wiki page for more info.
If you are trying to connect from outside heroku you need to connect with SSL. We only allow connections from outside heroku if they are encrypted with SSL
error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off says that you can't connect with SSL off.
Also you may be sanitizing your database name with database1, but if you're not, I can guarantee you that your database name is not, in fact, database1.
Also you should NOT NOT NOT be hard-coding your credentials in a file. Read them out of your environment.