4

Linux Pop! distribution (v 17 Ubuntu) Custom-built desktop machine

I've been working for a long time to try to get just a simple sequelize db:migrate command to work.

I have postgresql installed and if I do su - postgres and then psql I can get into the psql commannd prompt (and can also get out, using \q).

I'm working on a project where we need to use the sequelize-cli manager. I've installed npm i --save sequelize@4.32.6 pg@7.4.1 pg-hstore@2.3.2.

Then I did sequelize init in my directory, and adjusted the database files.

const path = require("path");

module.exports = {
  "config": path.resolve("./db/config", "config.json"),
  "models-path": path.resolve("./db/models"),
  "seeders-path": path.resolve("./db/seeds"),
  "migrations-path": path.resolve("./db/migrations")
};

And here's my config.json file for sequelize:

{
  "development": {
    "username": "postgres",
    "password": null,
    "database": "address-bloc-dev",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "logging": false
  },
  "test": {
    "username": "postgres",
    "password": null,
    "database": "address-bloc-test",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "logging": false
  }
}

No matter what I do, whenever I try to do sequelize db:migrate, I get this:

$ sequelize db:migrate

Sequelize CLI [Node: 6.11.4, CLI: 4.0.0, ORM: 4.32.6]

Loaded configuration file "db/config/config.json".
Using environment "development".
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:237:13

ERROR: password authentication failed for user "postgres"

I get this error whether I'm logged in as my main, normal user, or when I'm logged in as postgres. I can su between the two, navigate to the correct directory, and still get the same result.

I was earlier also getting another error, postgres is not in the sudoers file. This incident will be reported..

Per a recommendation on stackoverflow, I tried adding the postgres user to sudo usermod -a -G sudo postgres and made postgres an official account. It shows up on my login screen.

This did manage to make that second sudoers... error go away.

However, I still ultimately get the same password authentication failure... error.

I've also tried installing npm both as a regular user, and with the sudo command.

And I've tried going into the pg_hba.config file and changing peer to ident, per another recommendation on stackoverflow. No luck, still.

Any ideas about why I can't get sequelize-cli to perform this operation?

EDIT: I've received some kind responses, but so far I haven't been able to figure out what I'm doing wrong. Made some notes in a comment. Thank you.

anothermh
  • 9,815
  • 3
  • 33
  • 52
Blue Santa
  • 51
  • 5
  • If you've reconfigured it to use ident I guess you'll have to actually set up a password too and pass that? I'm fairly sure it doesn't use password authentication when you are the postgres user. – Rup Apr 23 '18 at 23:26
  • That is actually a security protection in postgresql configurations. You can't login in a third party client without a password, unless you configure it to do so. (pg_hba.conf file). So, setup a password and try adding it on your configuration. – Jorge Campos Apr 23 '18 at 23:28
  • Here are some info on that file: https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html – Jorge Campos Apr 23 '18 at 23:32
  • Thank for your responses. I've doing the `sequelize db:migrate` command with the `pg_hba.conf` file set both to `peer` and to `ident`. In both situations, I get the same result. I have a password set for `postgres`. It has a password both for the main account when you go to log in to `postgres` or `su` into it from the terminal. I also made sure that within `psql` it has a password (the same one). Not sure how they might be related? Anyway, all attempts still produce the same `authentication failed` result. – Blue Santa Apr 23 '18 at 23:36
  • 2
    In your configuration it is null `"password": null,` for both environments. Also when responding to comments always tag the people you are talking to using the `@` followed by the person name. That way we receive the notification. – Jorge Campos Apr 24 '18 at 01:06
  • @JorgeCampos Awesome, yes that turned out to be the issue. I needed to put the password into `./db/config/config.json`. Thank you! – Blue Santa Apr 24 '18 at 03:44
  • Hi Bryan, I am actually experiencing this exact same problem. When I run "sequelize db:migrate", I get that same ERROR message (I'm a student in Bloc and doing this same checkpoint). My dev environment is also Ubuntu, and I am also using psql. What password are we referring to here? When I installed psql, I don't recall ever setting a pw. @Jorge, could you please help shed some light on this matter? Currently, to log into psql console and query the databases, I just run "$ psql" and it takes me straight to the console – sansae Jul 15 '18 at 19:49
  • 1
    @user123456 take A look here https://serverfault.com/q/110154/234220 . It may be using the default password configured to access without it in local connections (same machine) – Jorge Campos Jul 15 '18 at 20:56
  • Hi @JorgeCampos. So to be clear, I should avoid setting a pw for UNIX account "postgres", but it's ok for me to set a pw for a psql account called "postgres"? If yes, I'll follow Chris James's suggestion (I'm ignorant, and [this post](https://stackoverflow.com/questions/36602509/can-someone-explain-how-postgresql-roles-postgresql-users-and-linux-users-relat) sums up my confusion well) – sansae Jul 15 '18 at 22:28
  • 1
    Yes. I would recommend creating a different user for your application though. See it here: https://stackoverflow.com/q/14734912/460557 @user123456 – Jorge Campos Jul 15 '18 at 22:35
  • When I run `$ psql`, I'm logged into the psql console. Then when I run `# \du`, I see two roles, "clark" and "postgres". When I run `# select current_user`, I see "clark". Is it perfectly fine to use "clark" for my web apps and just set a password for that using `# \password clark`? It seems all the databases I created in the past couple months were created under "clark". "clark" has these attribtues: Superuser, Create role, Create DB, but not Replication and Bypass RLS – sansae Jul 15 '18 at 22:55
  • I would not do that. An application user should have only needed permissions and that are often "connect, select, insert, update and delete. In some cases an application would need permission to select views and execute procedures". An user with `Superuser` can do almost anything in your database (or any database in the server), in case of a breach, the mess would be huge. @user123456 – Jorge Campos Jul 16 '18 at 00:58
  • This one is a good thread to read and keep in mind: https://stackoverflow.com/q/41537825/460557 @user123456 – Jorge Campos Jul 16 '18 at 01:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176029/discussion-between-user123456-and-jorge-campos). – sansae Jul 16 '18 at 01:48

0 Answers0