Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

password authentication failed with sequelize v4 replication

I am attempting to connect to my database(s) via replication. I have filled out the fields in the replication option in a variety of ways only to get the same error each time:

password authentication failed for user "my_local_system_username"

where somehow sequelize/pg thinks that I am trying to log in with my operating system user name???

Here is what I tried:

const serverParams = {
    user: auth.db.user,
    password: auth.db.password,
    port: 5432
};

const dbConfig = {
    options: {
        dialect: 'postgres',
        protocol: 'tcp',
        replication: {
            write: {},
            read: process.env.NODE_ENV === 'production' ?
                [
                    {
                        ...serverParams,
                        host: 'db1.lupoex.com'
                    },
                    {
                        ...serverParams,
                        host: 'db2.lupoex.com'
                    }
                ] :
                [
                    {
                        ...serverParams,
                        host: 'test.db.lupoex.com'
                    }
                ]
        },
        pool: {
            max: 5,
            min: 0,
            idle: 5000,
            acquire: 20000
        }
        //logging: function(query) {
        //    console.log(query)
        //}
    }
};

new Sequelize('database', null, null, dbConfig.options);

Thanks in advance, all comments/suggestions welcome.

like image 456
istrau2 Avatar asked Nov 15 '25 22:11

istrau2


2 Answers

Adding require('dotenv').config(); to the top of my config file fixed it for me.

More convo on the issue here: https://github.com/sequelize/cli/issues/641

like image 161
Mark Jackson Avatar answered Nov 17 '25 18:11

Mark Jackson


I figured this out. It seems the config needs a username like so:

const serverParams = {
    user: auth.db.user,
    username: auth.db.user,
    password: auth.db.password,
    port: 5432
};
like image 45
istrau2 Avatar answered Nov 17 '25 19:11

istrau2