2

I am using sequelize to connect to a postgres db which is hosted on compose.io.

const db = new Sequelize(DATABASE_URL, {
  logging: false,
  pool: {
    max: 15,
    min: 1,
    idle: 10000,
    acquire: 10000,
  },
});

How can I set a failover portal?

postgres://[username]:[password]@gcp-us-east1-cpu.2.dblayer.com:16070/compose
postgres://[username]:[password]@gcp-us-east1-cpu.0.dblayer.com:16070/compose
perrosnk
  • 835
  • 2
  • 13
  • 23
  • Have you tried setting up read replicas in the connection configuration? See https://sequelize.org/master/manual/read-replication.html for details, but it should just involve changing your `DATABASE_URL` to just the database, and adding hosts for each server in the `replication:` configuration key... – Timshel Apr 05 '20 at 10:10
  • This is only for read, right? – perrosnk Apr 05 '20 at 19:42
  • 1
    Yes it’s for handling replicas. What kind of redundancy are you using? If you’re doing failover clustering,your cluster OS should be providing a virtual IP address; in this case make sure you’re connecting to that address and it should failover without any involvement from Sequelize (other than reconnecting the dropped connections, which should happen automatically after timeout). – Timshel Apr 07 '20 at 09:43
  • 1
    The other way to accomplish failover is by using a connection pooler such as pgbouncer. Basically, Sequelize connects to the pooler, which proxies the connection to the current failover master. – Timshel Apr 07 '20 at 13:52

0 Answers0