def enable_as_master(self, service, master_config, for_failover=False): """For a server to be a master in postgres, we need to enable the replication user in pg_hba and ensure that WAL logging is at the appropriate level (use the same settings as backups) """ LOG.debug("Enabling as master, with cfg: %s ", master_config) self._get_or_create_replication_user(service) hba_entry = "host replication replicator 0.0.0.0/0 md5 \n" tmp_hba = '/tmp/pg_hba' operating_system.copy(service.pgsql_hba_config, tmp_hba, force=True, as_root=True) operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(), as_root=True) with open(tmp_hba, 'a+') as hba_file: hba_file.write(hba_entry) operating_system.copy(tmp_hba, service.pgsql_hba_config, force=True, as_root=True) operating_system.chmod(service.pgsql_hba_config, FileMode.SET_USR_RWX(), as_root=True) operating_system.remove(tmp_hba, as_root=True) service.reload_configuration()
def enable_as_master(self, service, master_config, for_failover=False): # For a server to be a master in postgres, we need to enable # replication user in pg_hba and ensure that WAL logging is # the appropriate level (use the same settings as backups) self._get_or_create_replication_user() hba_entry = "host replication replicator 0.0.0.0/0 md5 \n" tmp_hba = '/tmp/pg_hba' operating_system.copy(self.pgsql_hba_config, tmp_hba, force=True, as_root=True) operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(), as_root=True) with open(tmp_hba, 'a+') as hba_file: hba_file.write(hba_entry) operating_system.copy(tmp_hba, self.pgsql_hba_config, force=True, as_root=True) operating_system.chmod(self.pgsql_hba_config, FileMode.SET_USR_RWX(), as_root=True) operating_system.remove(tmp_hba, as_root=True) pgutil.psql("SELECT pg_reload_conf()")
def enable_as_master(self, service, master_config): """Primary postgredql settings. For a server to be a master in postgres, we need to enable the replication user in pg_hba.conf """ self._get_or_create_replication_user(service) hba_entry = f"host replication {REPL_USER} 0.0.0.0/0 md5\n" tmp_hba = '/tmp/pg_hba' operating_system.copy(pg_service.HBA_CONFIG_FILE, tmp_hba, force=True, as_root=True) operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(), as_root=True) with open(tmp_hba, 'a+') as hba_file: hba_file.write(hba_entry) operating_system.copy(tmp_hba, pg_service.HBA_CONFIG_FILE, force=True, as_root=True) operating_system.chown(pg_service.HBA_CONFIG_FILE, user=CONF.database_service_uid, group=CONF.database_service_uid, as_root=True) operating_system.chmod(pg_service.HBA_CONFIG_FILE, FileMode.SET_USR_RWX(), as_root=True) operating_system.remove(tmp_hba, as_root=True) LOG.debug(f"{pg_service.HBA_CONFIG_FILE} changed") service.restart()