Search code examples
postgresqlruntime-errorwindows-subsystem-for-linux

(PostgreSQL) 12.7 (Ubuntu 12.7-0ubuntu0.20.04.1) can't connect to the database?


This is on WSl 2 following the instructions from the official documentation

I created a simple postgresql and I try to connect to it like so:

const Sequelize = require("sequelize");

const sequelize = new Sequelize('postgres://postgres:w@localhost:5432/messenger', {
  logging: false,
  dialect: 'postgre'
});

async function test(){
  try {
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');
  } catch (error) {
    console.error('Unable to connect to the database:', error);
  }
}

test();
This will tell me if the connection was successful or not, but for some reason, I keep getting this error. The URI string seems correct, the only user is the default created Postgres where I changed the password to be "w" for testing purposes.

Not sure what that 12/main part is about but the server is online so I am really not sure what the problem is.

enter image description here

enter image description here


Solution

  • Either you specified the wrong password for the database user "postgres", or your server isn't configured to allow password authentication on localhost. You can see this link: https://www.postgresql.org/docs/current/auth-methods.html for more information on the authentication methods postgresql supports, or this one: https://www.postgresql.org/docs/current/auth-pg-hba-conf.html for information on how to set up authentication on your postgresql server.