(self, enable_archiving, can_restart)
Turn the archiving on or off
Turn the archiving on or off
Turn the archiving on or off
def master_configure_archiving(self, enable_archiving, can_restart):
        """Turn the archiving on or off"""

        cf = PostgresConfiguration(self, self.cf.getfile("master_config"))
        curr_archive_mode = cf.archive_mode()
        curr_wal_level = cf.wal_level()
        need_restart_warning = False

        if enable_archiving:
            # enable archiving
            cf_file = os.path.abspath(self.cf.filename)

            xarchive = "%s %s %s" % (self.script, cf_file, "xarchive %p %f")
            cf_params = { "archive_command": xarchive }

            if curr_archive_mode is not None:
                # archive mode specified in config, turn it on
                self.log.debug("found 'archive_mode' in config -- enabling it")
                cf_params["archive_mode"] = "on"

                if curr_archive_mode.lower() not in ('1', 'on', 'true') and not can_restart:
                    need_restart_warning = True

            if curr_wal_level is not None and curr_wal_level != 'hot_standby':
                # wal level set in config, enable it
                wal_level = self.cf.getboolean("hot_standby", False) and "hot_standby" or "archive"

                self.log.debug("found 'wal_level' in config -- setting to '%s'", wal_level)
                cf_params["wal_level"] = wal_level

                if curr_wal_level not in ("archive", "hot_standby") and not can_restart:
                    need_restart_warning = True

            if need_restart_warning:
                self.log.warning("database must be restarted to enable archiving")

        else:
            # disable archiving
            cf_params = dict()

            if can_restart:
                # can restart, disable archive mode and set wal_level to minimal

                cf_params['archive_command'] = ''

                if curr_archive_mode:
                    cf_params['archive_mode'] = 'off'
                if curr_wal_level:
                    cf_params['wal_level'] = 'minimal'
                    cf_params['max_wal_senders'] = '0'
            else:
                # not possible to change archive_mode or wal_level (requires restart),
                # so we just set the archive_command to /bin/true to avoid WAL pileup.
                self.log.info("database must be restarted to disable archiving")
                self.log.info("Setting archive_command to /bin/true to avoid WAL pileup")

                cf_params['archive_command'] = '/bin/true'

                # disable synchronous standbys, note that presently we don't care
                # if there is more than one standby.
                if cf.synchronous_standby_names():
                    cf_params['synchronous_standby_names'] = ''

        self.log.debug("modifying configuration: %s", cf_params)

        cf.modify(cf_params)
        cf.write()
def master_configure_archiving ( self , enable_archiving , can_restart ) : cf = PostgresConfiguration ( self , self . cf . getfile ( "master_config" ) ) curr_archive_mode = cf . archive_mode ( ) curr_wal_level = cf . wal_level ( ) need_restart_warning = False if enable_archiving : # enable archiving cf_file = os . path . abspath ( self . cf . filename ) xarchive = "%s %s %s" % ( self . script , cf_file , "xarchive %p %f" ) cf_params = { "archive_command" : xarchive } if curr_archive_mode is not None : # archive mode specified in config, turn it on self . log . debug ( "found 'archive_mode' in config -- enabling it" ) cf_params [ "archive_mode" ] = "on" if curr_archive_mode . lower ( ) not in ( '1' , 'on' , 'true' ) and not can_restart : need_restart_warning = True if curr_wal_level is not None and curr_wal_level != 'hot_standby' : # wal level set in config, enable it wal_level = self . cf . getboolean ( "hot_standby" , False ) and "hot_standby" or "archive" self . log . debug ( "found 'wal_level' in config -- setting to '%s'" , wal_level ) cf_params [ "wal_level" ] = wal_level if curr_wal_level not in ( "archive" , "hot_standby" ) and not can_restart : need_restart_warning = True if need_restart_warning : self . log . warning ( "database must be restarted to enable archiving" ) else : # disable archiving cf_params = dict ( ) if can_restart : # can restart, disable archive mode and set wal_level to minimal cf_params [ 'archive_command' ] = '' if curr_archive_mode : cf_params [ 'archive_mode' ] = 'off' if curr_wal_level : cf_params [ 'wal_level' ] = 'minimal' cf_params [ 'max_wal_senders' ] = '0' else : # not possible to change archive_mode or wal_level (requires restart), # so we just set the archive_command to /bin/true to avoid WAL pileup. self . log . info ( "database must be restarted to disable archiving" ) self . log . info ( "Setting archive_command to /bin/true to avoid WAL pileup" ) cf_params [ 'archive_command' ] = '/bin/true' # disable synchronous standbys, note that presently we don't care # if there is more than one standby. if cf . synchronous_standby_names ( ) : cf_params [ 'synchronous_standby_names' ] = '' self . log . debug ( "modifying configuration: %s" , cf_params ) cf . modify ( cf_params ) cf . write ( )