0
FATAL: no PostgreSQL user name specified in startup packet

Logs from my postgreSQL instance in my kubernetes cluster when trying to connect to it by doing the following:

const { POSTGRES_DATABASE, POSTGRES_USERNAME, POSTGRES_PASSWORD } = require('../config/config');

const Sequelize = require('sequelize');
    const conn = new Sequelize(POSTGRES_DATABASE, {
        username: POSTGRES_USERNAME,
        password: POSTGRES_PASSWORD
    });

config/config.js

    const config = {
        POSTGRES_DATABASE: 'postgres://postgres/postgresdb',
        POSTGRES_USERNAME: 'postgresadmin',
        POSTGRES_PASSWORD: 'admin123',
        SERVER_PORT: '5000'
    }

module.exports = config;

I am using SequelizeJS in nodeJS. http://docs.sequelizejs.com/

It seems like the requests are connecting alright due to seeing the attempts in the postgreSQL logs. However something goes wrong and I wonder if it's wrong with permissions in postgres or the node service.

Appreciate some help or ideas

13
  • is POSTGRES_USERNAME a variable? Where is it being defined? Commented Dec 30, 2018 at 14:55
  • I updated first post @doublesharp Commented Dec 30, 2018 at 14:57
  • 2
    You are passing in the username for the password - password: POSTGRES_USERNAME Commented Dec 30, 2018 at 15:48
  • 1
    Also, the database you’re using differs from the one in the configure. That’s seems odd. Commented Dec 30, 2018 at 15:53
  • 1
    I guess my point is, either use the one from your config.js, or delete it from config.js. Adding it to config.js and not using it is confusing and will lead to more confusion later. Commented Dec 30, 2018 at 15:55

1 Answer 1

3

According to the Sequelize documentation that you linked, the args to creating a new connection are db, username, password. Your code did db, and then an object with username and password keys. This object is not correct and caused it to not find the username or password. Try this instead:

const { POSTGRES_DATABASE, POSTGRES_USERNAME, POSTGRES_PASSWORD } = require('../config/config');

const Sequelize = require('sequelize');
const conn = new Sequelize(POSTGRES_DATABASE, POSTGRES_USERNAME, POSTGRES_PASSWORD);

Sequelize does allow for an optional options object as the last argument, but the username and password are not expected to be in there.

This page of the documentation feels confusing to me.

http://docs.sequelizejs.com/manual/installation/usage.html

I believe what it says is that you either need to define everything in the object, or do the database, username, and password as separate arguments, but I don’t see it supporting database in the arguments and username / password in the object.

It seems like this should work as well:

const conn = new Sequelize({
  database: POSTGRES_DATABASE,
  username: POSTGRES_USERNAME,
  password: POSTGRES_PASSWORD
});
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks buddy, nice catch. Now I get Error: connect ECONNREFUSED 127.0.0.1:5432 And it's not localhost I want to connect to, so I guess i'll need to define just the database name in the POSTGRES_DATABASE and then set a host somewhere in the options object
You need to add ahost to the options object then.
I now realize that my last comment ran together. A “host” key is what you need to specify, for it to know the IP address or domain of the database. It looks like you’ll also want to set dialect to 'postgres'. I’m uncertain if Sequelize is aware that Postgres runs on port 5432 by default. You may need to specify that as the “port” option as well.
I'm currently doing dialect: 'postgres', host: 'postgres' but it seems it doesn't reach the postgres service now at all. it says port is based of dialect so shouldnt be needed. // custom port; default: dialect default
Is node running directly on your computer? If you’re running it in a Docker container or a Virtual Machine, you may be having a problem with DNS not being shared from your computer to the VM.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.