11
Considerations with
pg_rewind
Target server (former leader)
all necessary WAL files must be either in pg_wal or in the archive
checksums must be enabled or wal_log_hints must be on
the parameter full_page_writes must be on
Source server (current leader)
clinet-server connection:
--source-server = connection string
cleanly shut down server:
--source-pgdata = directory
For the source server, if it is running, the --source-server switch specifies the
libpq client-server connection string (the utility does not use the replication
protocol). The connecting role must have the privileges required to run
pg_ls_dir, pg_stat_file, and pg_read_binary_file functions.
If the source server was shut down cleanly, you can just point to its data
directory with the --source-pgdata switch.
Several specific requirements must be met for the tool to work:
●
All WAL segments containing records from the last common checkpoint to
the current moment must be either in the target server's pg_wal directory
or present and available from the WAL archive.
In the second case, you need to set the restore_command parameter
and the --restore-target-wal switch.
●
Due to errors during writing, data mismatch within the pages is possible
(the non-atomic writing problem, discussed in the "Base backup" module).
This is solved by having the target server write each page's full image to
WAL after it is first changed since the checkpoint. This is enabled by
full_page_writes = on. This mode does ignores "minor" page changes
(hint bits), so the cluster also must either have page checksum calculation
enabled or have wal_log_hints = on.
●
If the target server was shut down incorrectly and without a checkpoint,
the tool will start it in single-user mode and immediately perform a clean
shutdown.