In the scenario where master/replica postgres connections are built using pg-promise
, is there a way to rebuild these connections in case of replica outages?
Instead of doing process.exitCode = 1;
in the error function passed with the initOptions and rebuilding only working connections on service start-up... Is there a better way to remove the failing connection (even better if its a replica and process.exitCode if its a primary)?
const initOptions = {
// global event notification;
error: (error, e) => {
if (e.cn) {
//log
}
process.exitCode =1;
}
};
//singleton
const pgp = require('pg-promise')(initOptions);
// then for each database in config, we connect and start the service
pgp.end()
but then the application needs to know to stop accepting connections in the meantime – Luigi