From 61081e75c6741024f7717ade0450090590e96c85 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 23 Mar 2015 19:47:52 +0200 Subject: Add pg_rewind, for re-synchronizing a master server after failback. Earlier versions of this tool were available (and still are) on github. Thanks to Michael Paquier, Alvaro Herrera, Peter Eisentraut, Amit Kapila, and Satoshi Nagayasu for review. --- doc/src/sgml/high-availability.sgml | 4 +- doc/src/sgml/ref/allfiles.sgml | 1 + doc/src/sgml/ref/pg_rewind.sgml | 237 ++++++++++++++++++++++++++++++++++++ doc/src/sgml/reference.sgml | 1 + 4 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 doc/src/sgml/ref/pg_rewind.sgml (limited to 'doc') diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml index d249959f205..a17f55545c9 100644 --- a/doc/src/sgml/high-availability.sgml +++ b/doc/src/sgml/high-availability.sgml @@ -1272,7 +1272,9 @@ primary_slot_name = 'node_a_slot' and might stay down. To return to normal operation, a standby server must be recreated, either on the former primary system when it comes up, or on a third, - possibly new, system. Once complete, the primary and standby can be + possibly new, system. The utility can be + used to speed up this process on large clusters. + Once complete, the primary and standby can be considered to have switched roles. Some people choose to use a third server to provide backup for the new primary until the new standby server is recreated, diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml index 7aa3128090d..5b4692fb6d8 100644 --- a/doc/src/sgml/ref/allfiles.sgml +++ b/doc/src/sgml/ref/allfiles.sgml @@ -190,6 +190,7 @@ Complete list of usable sgml source files in this directory. + diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml new file mode 100644 index 00000000000..37b5d673ce2 --- /dev/null +++ b/doc/src/sgml/ref/pg_rewind.sgml @@ -0,0 +1,237 @@ + + + + + pg_rewind + + + + pg_rewind + 1 + Application + + + + pg_rewind + synchronize a PostgreSQL data directory with another data directory that was forked from the first one + + + + + pg_rewind + option + + + + + + directory + + + + + + + + + + Description + + + pg_rewind is a tool for synchronizing a PostgreSQL cluster + with another copy of the same cluster, after the clusters' timelines have + diverged. A typical scenario is to bring an old master server back online + after failover, as a standby that follows the new master. + + + + The result is equivalent to replacing the target data directory with the + source one. All files are copied, including configuration files. The + advantage of pg_rewind over taking a new base backup, or + tools like rsync, is that pg_rewind does + not require reading through all unchanged files in the cluster. That makes + it a lot faster when the database is large and only a small portion of it + differs between the clusters. + + + + pg_rewind examines the timeline histories of the source + and target clusters to determine the point where they diverged, and + expects to find WAL in the target cluster's pg_xlog directory + reaching all the way back to the point of divergence. In the typical + failover scenario where the target cluster was shut down soon after the + divergence, that is not a problem, but if the target cluster had run for a + long time after the divergence, the old WAL files might not be present + anymore. In that case, they can be manually copied from the WAL archive to + the pg_xlog directory. Fetching missing files from a WAL + archive automatically is currently not supported. + + + + When the target server is started up for the first time after running + pg_rewind, it will go into recovery mode and replay all + WAL generated in the source server after the point of divergence. + If some of the WAL was no longer available in the source server when + pg_rewind was run, and therefore could not be copied by + pg_rewind session, it needs to be made available when the + target server is started up. That can be done by creating a + recovery.conf file in the target data directory with a + suitable restore_command. + + + + + Options + + + pg_rewind accepts the following command-line + arguments: + + + + + + + + This option specifies the target data directory that is synchronized + with the source. The target server must shut down cleanly before + running pg_rewind + + + + + + + + + Specifies path to the data directory of the source server, to + synchronize the target with. When + + + + + + + + Specifies a libpq connection string to connect to the source + PostgreSQL server to synchronize the target with. + The server must be up and running, and must not be in recovery mode. + + + + + + + + + + Do everything except actually modifying the target directory. + + + + + + + + + + Enables progress reporting. Turning this on will deliver an approximate + progress report while copying data over from the source cluster. + + + + + + + + + Print verbose debugging output that is mostly useful for developers + debugging pg_rewind. + + + + + + + + Display version information, then exit + + + + + + Show help, then exit + + + + + + + + Environment + + + When + + + + Notes + + + pg_rewind requires that the wal_log_hints + option is enabled in postgresql.conf, or that data checksums + were enabled when the cluster was initialized with initdb. + full_page_writes must also be enabled. + + + + How it works + + + The basic idea is to copy everything from the new cluster to the old + cluster, except for the blocks that we know to be the same. + + + + + + Scan the WAL log of the old cluster, starting from the last checkpoint + before the point where the new cluster's timeline history forked off + from the old cluster. For each WAL record, make a note of the data + blocks that were touched. This yields a list of all the data blocks + that were changed in the old cluster, after the new cluster forked off. + + + + + Copy all those changed blocks from the new cluster to the old cluster. + + + + + Copy all other files like clog, conf files etc. from the new cluster + to old cluster. Everything except the relation files. + + + + + Apply the WAL from the new cluster, starting from the checkpoint + created at failover. (Strictly speaking, pg_rewind + doesn't apply the WAL, it just creates a backup label file indicating + that when PostgreSQL is started, it will start replay + from that checkpoint and apply all the required WAL.) + + + + + + + diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml index 10c9a6d4030..65ad795afe9 100644 --- a/doc/src/sgml/reference.sgml +++ b/doc/src/sgml/reference.sgml @@ -260,6 +260,7 @@ &pgControldata; &pgCtl; &pgResetxlog; + &pgRewind; &postgres; &postmaster; -- cgit v1.2.3