summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMartin Pihlak2010-07-27 08:38:36 +0000
committerMartin Pihlak2010-07-27 09:11:53 +0000
commitf59838c89d9849df13669c624f247cd90ec37269 (patch)
tree51513fe8c233018d7a69f0f39430947bfd750dbb /python
parent1cc37e1ac88c7f932fce59dbdaa8d98e1d139a59 (diff)
Introduce a 'slave_pg_xlog' configuration variable. This
allows master and slave pg_xlog files to be in different locations. During restore this directory is symlinked to slave pg_xlog. Patch from Steve Singer.
Diffstat (limited to 'python')
-rw-r--r--python/conf/wal-slave.ini3
-rwxr-xr-xpython/walmgr.py32
2 files changed, 28 insertions, 7 deletions
diff --git a/python/conf/wal-slave.ini b/python/conf/wal-slave.ini
index 9e6b3337..66ebd632 100644
--- a/python/conf/wal-slave.ini
+++ b/python/conf/wal-slave.ini
@@ -9,6 +9,9 @@ slave_stop_cmd = /etc/init.d/postgresql-8.3 stop
slave_start_cmd = /etc/init.d/postgresql-8.3 start
slave_config_dir = /etc/postgresql/8.3/main
+# alternative pg_xlog directory for slave, symlinked to pg_xlog on restore
+#slave_pg_xlog = /vol2/pg_xlog
+
slave = /var/lib/postgresql/walshipping
completed_wals = %(slave)s/logs.complete
partial_wals = %(slave)s/logs.partial
diff --git a/python/walmgr.py b/python/walmgr.py
index 81a2e0b1..fe7263b7 100755
--- a/python/walmgr.py
+++ b/python/walmgr.py
@@ -1325,20 +1325,38 @@ STOP TIME: %(stop_time)s
# move new data, copy if setname specified
self.log.info("%s %s to %s" % (setname and "Copy" or "Move", full_dir, data_dir))
+
+ if self.cf.get('slave_pg_xlog', ''):
+ link_xlog_dir = True
+ exclude_pg_xlog = '--exclude=pg_xlog'
+ else:
+ link_xlog_dir = False
+ exclude_pg_xlog = ''
+
if not self.not_really:
- if not setname:
+ if not setname and not link_xlog_dir:
os.rename(full_dir, data_dir)
else:
- self.exec_rsync(["--delete", "--no-relative", "--exclude=pg_xlog/*",
- os.path.join(full_dir,""), data_dir], True)
- if self.wtype == MASTER and createbackup and os.path.isdir(bak):
+ rsync_args=["--delete", "--no-relative", "--exclude=pg_xlog/*"]
+ if exclude_pg_xlog:
+ rsync_args.append(exclude_pg_xlog)
+ rsync_args += [os.path.join(full_dir, ""), data_dir]
+
+ self.exec_rsync(rsync_args, True)
+
+ if link_xlog_dir:
+ os.symlink(self.cf.get('slave_pg_xlog'), "%s/pg_xlog" % data_dir)
+
+ if (self.wtype == MASTER and createbackup and os.path.isdir(bak)):
# restore original xlog files to data_dir/pg_xlog
- # symlinked directories are dereferences
- self.exec_cmd(["cp", "-rL", "%s/pg_xlog" % bak, data_dir])
+ # symlinked directories are dereferenced
+ self.exec_cmd(["cp", "-rL", "%s/pg_xlog/" % full_dir, "%s/pg_xlog" % data_dir ])
else:
# create an archive_status directory
xlog_dir = os.path.join(data_dir, "pg_xlog")
- os.mkdir(os.path.join(xlog_dir, "archive_status"), 0700)
+ archive_path = os.path.join(xlog_dir, "archive_status")
+ if not os.path.exists(archive_path):
+ os.mkdir(archive_path, 0700)
else:
data_dir = full_dir