(self)
Manage synchronous_standby_names parameter
Manage synchronous_standby_names parameter
Manage synchronous_standby_names parameter
def master_synch_standby(self):
        """Manage synchronous_standby_names parameter"""

        if self.options.synchronous_standby_names is None:
            if len(self.args) < 1:
                die(1, "usage: synch-standby SYNCHRONOUS_STANDBY_NAMES")

            names = self.args[0]
            self.assert_is_master(True)
        else:
            # as synchronous_standby_names is available since 9.1
            # we can override DEFAULT_PG_VERSION
            global DEFAULT_PG_VERSION
            DEFAULT_PG_VERSION = "9.1"

            self.guess_locations()
            self.override_cf_option('master_config', self.postgres_conf)
            self.override_cf_option('master_data', self.pgdata)
            self.override_cf_option('master_db', 'dbname=template1')
            names = self.options.synchronous_standby_names

        cf = PostgresConfiguration(self, self.cf.getfile("master_config"))

        # list of slaves
        db = self.get_database("master_db")
        cur = db.cursor()
        cur.execute("select application_name from pg_stat_replication")
        slave_names = [slave[0] for slave in cur.fetchall()]
        self.close_database("master_db")

        if names.strip() == "":
            if not self.not_really:
                cf.set_synchronous_standby_names("")
            return

        if names.strip() == "*":
            if slave_names:
                if not self.not_really:
                    cf.set_synchronous_standby_names(names)
                return
            else:
                die(1,"At least one slave must be available when enabling synchronous mode")

        # ensure that at least one slave is available from new parameter value
        slave_found = None
        for new_synch_slave in re.findall(r"[^\s,]+",names):
            if new_synch_slave not in slave_names:
                self.log.warning("No slave available with name %s", new_synch_slave)
            else:
                slave_found = True
                break

        if not slave_found:
            die(1,"At least one slave must be available from new list when enabling synchronous mode")
        elif not self.not_really:
            cf.set_synchronous_standby_names(names)
def master_synch_standby ( self ) : if self . options . synchronous_standby_names is None : if len ( self . args ) < 1 : die ( 1 , "usage: synch-standby SYNCHRONOUS_STANDBY_NAMES" ) names = self . args [ 0 ] self . assert_is_master ( True ) else : # as synchronous_standby_names is available since 9.1 # we can override DEFAULT_PG_VERSION global DEFAULT_PG_VERSION DEFAULT_PG_VERSION = "9.1" self . guess_locations ( ) self . override_cf_option ( 'master_config' , self . postgres_conf ) self . override_cf_option ( 'master_data' , self . pgdata ) self . override_cf_option ( 'master_db' , 'dbname=template1' ) names = self . options . synchronous_standby_names cf = PostgresConfiguration ( self , self . cf . getfile ( "master_config" ) ) # list of slaves db = self . get_database ( "master_db" ) cur = db . cursor ( ) cur . execute ( "select application_name from pg_stat_replication" ) slave_names = [ slave [ 0 ] for slave in cur . fetchall ( ) ] self . close_database ( "master_db" ) if names . strip ( ) == "" : if not self . not_really : cf . set_synchronous_standby_names ( "" ) return if names . strip ( ) == "*" : if slave_names : if not self . not_really : cf . set_synchronous_standby_names ( names ) return else : die ( 1 , "At least one slave must be available when enabling synchronous mode" ) # ensure that at least one slave is available from new parameter value slave_found = None for new_synch_slave in re . findall ( r"[^\s,]+" , names ) : if new_synch_slave not in slave_names : self . log . warning ( "No slave available with name %s" , new_synch_slave ) else : slave_found = True break if not slave_found : die ( 1 , "At least one slave must be available from new list when enabling synchronous mode" ) elif not self . not_really : cf . set_synchronous_standby_names ( names )