Strapi with Postgres Failover Database connection string

698 Views Asked by At

I have setup the postgres with repmgr and Configured as Replication and Failover between two servers , The Failover Setup is working fine. The Connection string of Postgres is given below.

postgres://repmgr:[email protected]:5432,10.200.0.120:5432/Stag_DB

when I tried to setup the strapi with this postgres string , I have not found any article to connect postgres string with strapi. I am following this link https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#database only found database.js file in strapi project which connect one DB at one time.

  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        host: env('DATABASE_HOST', 'localhost'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        username: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        schema: env('DATABASE_SCHEMA', 'public'), // Not Required
        ssl: {
          rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
        },
      },
      options: {
        ssl: env.bool('DATABASE_SSL', false),
      },
    },
  },
}); 

This will only connect one DB at one time Please Help me to connect this string postgres://repmgr:[email protected]:5423,10.200.0.120:5423/Stag_DB on strapi.

1

There are 1 best solutions below

0
On

I've tried it with mongodb database, I don't know it might work in postgre, but here the step :

  1. Update database.js file into something like this
module.exports = ({ env }) => ({
    defaultConnection: 'default',
    connections: {
        default: {
            connector: 'mongoose',
            settings: {
                uri: env('DATABASE_URI'),
            },
            options: {
                ssl: true,
            }
        }
    }
});
  1. Update your .env file with your database string, e.g:
  DATABASE_URI=mongodb://username:[email protected]/myFirstDatabase?retryWrites=true&w=majority