diff options
author | Martin Pihlak | 2010-12-09 15:32:00 +0000 |
---|---|---|
committer | Martin Pihlak | 2010-12-09 15:32:00 +0000 |
commit | 785ea94b5cdd313cd128014c42e7fcd8a6552bd5 (patch) | |
tree | 3df5fcfb0a312878b60f33b3348cfee6cffd9e38 /python/walmgr.py | |
parent | dd9e05f609061de3dde7651b34f7fce95c2ff96c (diff) |
Some adjustments for 9.0, wal_level GUC is also modified during setup/stop.
Diffstat (limited to 'python/walmgr.py')
-rwxr-xr-x | python/walmgr.py | 84 |
1 files changed, 59 insertions, 25 deletions
diff --git a/python/walmgr.py b/python/walmgr.py index fe7263b7..14752c2d 100755 --- a/python/walmgr.py +++ b/python/walmgr.py @@ -207,29 +207,40 @@ class PostgresConfiguration: return "off" return None + def wal_level(self): + """Return value for specified parameter""" + # see if explicitly set + m = re.search("^\s*wal_level\s*=\s*'?([a-z_]+)'?\s*#?.*$", self.cf_buf, re.M | re.I) + if m: + return m.group(1) + # also, it could be commented out as initdb leaves it + # it'd probably be best to check from the database ... + m = re.search("^#wal_level\s*=.*$", self.cf_buf, re.M | re.I) + if m: + return "minimal" + return None + def modify(self, cf_params): """Change the configuration parameters supplied in cf_params""" for (param, value) in cf_params.iteritems(): - r_active = re.compile("^[ ]*%s[ ]*=[ ]*'(.*)'.*$" % param, re.M) - r_disabled = re.compile("^.*%s.*$" % param, re.M) + r_active = re.compile("^\s*%s\s*=\s*([^\s#]*).*$" % param, re.M) + r_disabled = re.compile("^\s*#\s*%s\s*=.*$" % param, re.M) cf_full = "%s = '%s'" % (param, value) m = r_active.search(self.cf_buf) if m: old_val = m.group(1) - if old_val == value: - self.log.debug("parameter %s already set to '%s'" % (param, value)) - else: - self.log.debug("found parameter %s with value '%s'" % (param, old_val)) - self.cf_buf = "%s%s%s" % (self.cf_buf[:m.start()], cf_full, self.cf_buf[m.end():]) + self.log.debug("found parameter %s with value '%s'" % (param, old_val)) + self.cf_buf = "%s%s%s" % (self.cf_buf[:m.start()], cf_full, self.cf_buf[m.end():]) else: m = r_disabled.search(self.cf_buf) if m: self.log.debug("found disabled parameter %s" % param) self.cf_buf = "%s\n%s%s" % (self.cf_buf[:m.end()], cf_full, self.cf_buf[m.end():]) else: + # not found, append to the end self.log.debug("found no value") self.cf_buf = "%s\n%s\n\n" % (self.cf_buf, cf_full) @@ -519,38 +530,61 @@ class WalMgr(skytools.DBScript): """Turn the archiving on or off""" cf = PostgresConfiguration(self, self.cf.get("master_config")) - archive_mode = cf.archive_mode() + 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 archive_mode: + 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 archive_mode.lower() not in ('1', 'on', 'true') and not can_restart: - self.log.warning("database must be restarted to enable archiving") - else: - self.log.debug("seems that archive_mode is not set, ignoring it.") + 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 - if not archive_mode: - # archive_mode not set, just reset archive_command and its done - self.log.debug("archive_mode not set in config, leaving as is") - cf_params = { "archive_command": "" } - elif can_restart: - # restart possible, turn off archiving, reset archive_command - cf_params = { "archive_mode": "off", "archive_command": "" } - else: - # not possible to change archive_mode (requires restart), so we - # just set the archive_command to /bin/true to avoid WAL pileup. - self.log.debug("master_restart_cmd not specified, leaving archive_mode as is") - cf_params = { "archive_command": "/bin/true" } + + cf_params = { + "archive_mode": "off", + "wal_level": "minimal", + "archive_command": "" + } + + if curr_archive_mode is None: + self.log.info("archive_mode not set") + del(cf_params['archive_mode']) + + if curr_wal_level is None: + self.log.info("wal_level not set") + del(cf_params['wal_level']) + + if not can_restart: + # 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.warning("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' self.log.debug("modifying configuration: %s" % cf_params) |