Introduce a 'slave_pg_xlog' configuration variable. This
authorMartin Pihlak <martin.pihlak@gmail.com>
Tue, 27 Jul 2010 08:38:36 +0000 (11:38 +0300)
committerMartin Pihlak <martin.pihlak@gmail.com>
Tue, 27 Jul 2010 09:11:53 +0000 (12:11 +0300)
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.

doc/walmgr.txt
python/conf/wal-slave.ini
python/walmgr.py

index 62d263af42c25fb4900fc7ff988107582edfed58..e76be3e87e3621beb9525099cfe446499972c401 100644 (file)
@@ -274,6 +274,12 @@ Script to execute before rotating away the oldest backup. If it fails
 backups will not be rotated.
 
 
+==== slave_pg_xlog ====
+Set slave_pg_xlog to the directory on the slave where pg_xlog files get 
+written to. On a restore to the slave walmgr.py will
+create a symbolic link from data/pg_xlog to this location.
+
+
 ==== backup_datadir ====
 Set backup_datadir to 'no' to prevent walmgr.py from making a backup
 of the data directory when restoring to the slave.  This defaults to
index 9e6b333710e827a252f893bfd5805572aa8a6871..66ebd632adaf84739e35fe3debc89008fb812d22 100644 (file)
@@ -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
index 81a2e0b1720176064f17ec6af8b8d2dd0f68d14d..fe7263b7bf4ec470ffc2eb5d56021cfd746c259f 100755 (executable)
@@ -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