8

I would like to connect to Postgres using Sequelize over Unix socket (not over localhost).

Postgres is configured to accept Unix socket connections from user pgdba. All works from command line with psql. So the Pg side is correctly configured.

I can't seem to find Sequelize configuration though to support Unix sockets. Closest I could find was for mysql, which I've adapted for Pg, but doesn't seem to work:

var sequelizeConfig = {
    dialect: 'postgres',
    dialectOptions: {
        socketPath: '/home/pgdba/data/5432/.s.PGSQL.5432',
    }
    port: 5432
};
var sequelize = new Sequelize('fooDb', 'pgdba', 'passwd', sequelizeConfig);

The error I'm getting when starting the app:

Unable to connect to the database: +23ms { [SequelizeConnectionError: pg_hba.conf rejects connection for host "127.0.0.1", user "pgdba", database "fooDb"]
  name: 'SequelizeConnectionError',
  message: 'pg_hba.conf rejects connection for host "127.0.0.1", user "pgdba", database "fooDb"',...

Apparently sequelize is still trying to go over localhost instead of the Unix socket and the pg_hba.conf is correctly rejecting it, as is configured. Is there a way to configure Sequelize for Postgres and Unix socket?

Using Sequelize 3.14.2 on Node v5.1.0 and Postgresql 9.5.0beta2.

2
  • 1
    I used the same config as you described and it worked like a charm! As I don't have a username or password for the db, I left those fields blank.
    – andHapp
    Commented May 25, 2016 at 22:11
  • 3
    I used the socketPath with mysql and it worked for me but format for socketPath that we have to provide is /cloudsql/[instance_connection_name]. Here instance_conneciton_name you can find it inside cloud sql page below public ip address section. Commented May 8, 2019 at 9:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.