2015-03-23 18:47:52 +01:00
|
|
|
<!--
|
|
|
|
doc/src/sgml/ref/pg_rewind.sgml
|
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="app-pgrewind">
|
|
|
|
<indexterm zone="app-pgrewind">
|
|
|
|
<primary>pg_rewind</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle><application>pg_rewind</application></refentrytitle>
|
|
|
|
<manvolnum>1</manvolnum>
|
|
|
|
<refmiscinfo>Application</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>pg_rewind</refname>
|
2016-08-01 18:52:22 +02:00
|
|
|
<refpurpose>synchronize a <productname>PostgreSQL</productname> data directory with another data directory that was forked from it</refpurpose>
|
2015-03-23 18:47:52 +01:00
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<cmdsynopsis>
|
|
|
|
<command>pg_rewind</command>
|
|
|
|
<arg rep="repeat"><replaceable>option</replaceable></arg>
|
|
|
|
<group choice="plain">
|
|
|
|
<group choice="req">
|
2021-04-24 03:44:13 +02:00
|
|
|
<arg choice="plain"><option>-D</option></arg>
|
2015-03-23 18:47:52 +01:00
|
|
|
<arg choice="plain"><option>--target-pgdata</option></arg>
|
|
|
|
</group>
|
|
|
|
<replaceable> directory</replaceable>
|
|
|
|
<group choice="req">
|
|
|
|
<arg choice="plain"><option>--source-pgdata=<replaceable>directory</replaceable></option></arg>
|
|
|
|
<arg choice="plain"><option>--source-server=<replaceable>connstr</replaceable></option></arg>
|
|
|
|
</group>
|
|
|
|
</group>
|
|
|
|
</cmdsynopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>pg_rewind</application> is a tool for synchronizing a PostgreSQL cluster
|
2015-03-23 18:47:52 +01:00
|
|
|
with another copy of the same cluster, after the clusters' timelines have
|
2020-06-15 19:12:58 +02:00
|
|
|
diverged. A typical scenario is to bring an old primary server back online
|
|
|
|
after failover as a standby that follows the new primary.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-05-01 10:40:41 +02:00
|
|
|
After a successful rewind, the state of the target data directory is
|
|
|
|
analogous to a base backup of the source data directory. Unlike taking
|
|
|
|
a new base backup or using a tool like <application>rsync</application>,
|
|
|
|
<application>pg_rewind</application> does not require comparing or copying
|
|
|
|
unchanged relation blocks in the cluster. Only changed blocks from existing
|
|
|
|
relation files are copied; all other files, including new relation files,
|
|
|
|
configuration files, and WAL segments, are copied in full. As such the
|
|
|
|
rewind operation is significantly faster than other approaches when the
|
|
|
|
database is large and only a small fraction of blocks differ between the
|
|
|
|
clusters.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>pg_rewind</application> examines the timeline histories of the source
|
2015-03-23 18:47:52 +01:00
|
|
|
and target clusters to determine the point where they diverged, and
|
2017-10-09 03:44:17 +02:00
|
|
|
expects to find WAL in the target cluster's <filename>pg_wal</filename> directory
|
2015-12-01 16:56:44 +01:00
|
|
|
reaching all the way back to the point of divergence. The point of divergence
|
2016-08-01 18:52:22 +02:00
|
|
|
can be found either on the target timeline, the source timeline, or their common
|
2015-12-01 16:56:44 +01:00
|
|
|
ancestor. In the typical failover scenario where the target cluster was
|
2016-08-01 18:52:22 +02:00
|
|
|
shut down soon after the divergence, this is not a problem, but if the
|
2020-04-01 03:57:03 +02:00
|
|
|
target cluster ran for a long time after the divergence, its old WAL
|
|
|
|
files might no longer be present. In this case, you can manually copy them
|
|
|
|
from the WAL archive to the <filename>pg_wal</filename> directory, or run
|
|
|
|
<application>pg_rewind</application> with the <literal>-c</literal> option to
|
|
|
|
automatically retrieve them from the WAL archive. The use of
|
2020-09-01 00:33:37 +02:00
|
|
|
<application>pg_rewind</application> is not limited to failover, e.g., a standby
|
2020-11-02 07:14:41 +01:00
|
|
|
server can be promoted, run some write transactions, and then rewound
|
2016-08-01 18:52:22 +02:00
|
|
|
to become a standby again.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-05-01 10:40:41 +02:00
|
|
|
After running <application>pg_rewind</application>, WAL replay needs to
|
|
|
|
complete for the data directory to be in a consistent state. When the
|
|
|
|
target server is started again it will enter archive recovery and replay
|
|
|
|
all WAL generated in the source server from the last checkpoint before
|
|
|
|
the point of divergence. If some of the WAL was no longer available in the
|
|
|
|
source server when <application>pg_rewind</application> was run, and
|
|
|
|
therefore could not be copied by the <application>pg_rewind</application>
|
|
|
|
session, it must be made available when the target server is started.
|
|
|
|
This can be done by creating a <filename>recovery.signal</filename> file
|
|
|
|
in the target data directory and by configuring a suitable
|
|
|
|
<xref linkend="guc-restore-command"/> in
|
|
|
|
<filename>postgresql.conf</filename>.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
2015-09-18 02:56:58 +02:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>pg_rewind</application> requires that the target server either has
|
2017-11-23 15:39:47 +01:00
|
|
|
the <xref linkend="guc-wal-log-hints"/> option enabled
|
2017-10-09 03:44:17 +02:00
|
|
|
in <filename>postgresql.conf</filename> or data checksums enabled when
|
|
|
|
the cluster was initialized with <application>initdb</application>. Neither of these
|
2017-11-23 15:39:47 +01:00
|
|
|
are currently on by default. <xref linkend="guc-full-page-writes"/>
|
2017-10-09 03:44:17 +02:00
|
|
|
must also be set to <literal>on</literal>, but is enabled by default.
|
2015-09-18 02:56:58 +02:00
|
|
|
</para>
|
2018-07-07 01:10:10 +02:00
|
|
|
|
|
|
|
<warning>
|
2023-06-23 14:14:57 +02:00
|
|
|
<title>Warning: Failures While Rewinding</title>
|
2018-07-07 01:10:10 +02:00
|
|
|
<para>
|
|
|
|
If <application>pg_rewind</application> fails while processing, then
|
|
|
|
the data folder of the target is likely not in a state that can be
|
|
|
|
recovered. In such a case, taking a new fresh backup is recommended.
|
|
|
|
</para>
|
|
|
|
|
2020-05-01 10:40:41 +02:00
|
|
|
<para>
|
|
|
|
As <application>pg_rewind</application> copies configuration files
|
|
|
|
entirely from the source, it may be required to correct the configuration
|
|
|
|
used for recovery before restarting the target server, especially if
|
|
|
|
the target is reintroduced as a standby of the source. If you restart
|
|
|
|
the server after the rewind operation has finished but without configuring
|
|
|
|
recovery, the target may again diverge from the primary.
|
|
|
|
</para>
|
|
|
|
|
2018-07-07 01:10:10 +02:00
|
|
|
<para>
|
|
|
|
<application>pg_rewind</application> will fail immediately if it finds
|
|
|
|
files it cannot write directly to. This can happen for example when
|
|
|
|
the source and the target server use the same file mapping for read-only
|
|
|
|
SSL keys and certificates. If such files are present on the target server
|
|
|
|
it is recommended to remove them before running
|
|
|
|
<application>pg_rewind</application>. After doing the rewind, some of
|
|
|
|
those files may have been copied from the source, in which case it may
|
|
|
|
be necessary to remove the data copied and restore back the set of links
|
|
|
|
used before the rewind.
|
|
|
|
</para>
|
|
|
|
</warning>
|
2015-03-23 18:47:52 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<application>pg_rewind</application> accepts the following command-line
|
|
|
|
arguments:
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2015-04-03 05:21:16 +02:00
|
|
|
<term><option>-D <replaceable class="parameter">directory</replaceable></option></term>
|
|
|
|
<term><option>--target-pgdata=<replaceable class="parameter">directory</replaceable></option></term>
|
2015-03-23 18:47:52 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option specifies the target data directory that is synchronized
|
2016-08-01 18:52:22 +02:00
|
|
|
with the source. The target server must be shut down cleanly before
|
2015-03-23 18:47:52 +01:00
|
|
|
running <application>pg_rewind</application>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2015-04-03 05:21:16 +02:00
|
|
|
<term><option>--source-pgdata=<replaceable class="parameter">directory</replaceable></option></term>
|
2015-03-23 18:47:52 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-08-01 18:52:22 +02:00
|
|
|
Specifies the file system path to the data directory of the source
|
|
|
|
server to synchronize the target with. This option requires the
|
|
|
|
source server to be cleanly shut down.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2015-04-03 05:21:16 +02:00
|
|
|
<term><option>--source-server=<replaceable class="parameter">connstr</replaceable></option></term>
|
2015-03-23 18:47:52 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies a libpq connection string to connect to the source
|
2019-04-05 03:37:59 +02:00
|
|
|
<productname>PostgreSQL</productname> server to synchronize the target
|
|
|
|
with. The connection must be a normal (non-replication) connection
|
|
|
|
with a role having sufficient permissions to execute the functions
|
|
|
|
used by <application>pg_rewind</application> on the source server
|
|
|
|
(see Notes section for details) or a superuser role. This option
|
2020-11-12 13:52:24 +01:00
|
|
|
requires the source server to be running and accepting connections.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2019-09-30 17:57:35 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-R</option></term>
|
|
|
|
<term><option>--write-recovery-conf</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Create <filename>standby.signal</filename> and append connection
|
|
|
|
settings to <filename>postgresql.auto.conf</filename> in the output
|
|
|
|
directory. <literal>--source-server</literal> is mandatory with
|
|
|
|
this option.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2015-03-23 18:47:52 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-n</option></term>
|
|
|
|
<term><option>--dry-run</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Do everything except actually modifying the target directory.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2018-07-10 01:51:10 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-N</option></term>
|
|
|
|
<term><option>--no-sync</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
By default, <command>pg_rewind</command> will wait for all files
|
|
|
|
to be written safely to disk. This option causes
|
|
|
|
<command>pg_rewind</command> to return without waiting, which is
|
|
|
|
faster, but means that a subsequent operating system crash can leave
|
2022-04-12 23:15:02 +02:00
|
|
|
the data directory corrupt. Generally, this option is useful for
|
|
|
|
testing but should not be used on a production
|
2018-07-10 01:51:10 +02:00
|
|
|
installation.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2015-03-23 18:47:52 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-P</option></term>
|
|
|
|
<term><option>--progress</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Enables progress reporting. Turning this on will deliver an approximate
|
2016-08-01 18:52:22 +02:00
|
|
|
progress report while copying data from the source cluster.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2020-04-01 03:57:03 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-c</option></term>
|
|
|
|
<term><option>--restore-target-wal</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Use <varname>restore_command</varname> defined in the target cluster
|
|
|
|
configuration to retrieve WAL files from the WAL archive if these
|
|
|
|
files are no longer available in the <filename>pg_wal</filename>
|
|
|
|
directory.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2022-04-07 01:51:49 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>--config-file=<replaceable class="parameter">filename</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Use the specified main server configuration file for the target
|
|
|
|
cluster. This affects <application>pg_rewind</application> when
|
|
|
|
it uses internally the <application>postgres</application> command
|
|
|
|
for the rewind operation on this cluster (when retrieving
|
|
|
|
<varname>restore_command</varname> with the option
|
|
|
|
<option>-c/--restore-target-wal</option> and when forcing a
|
|
|
|
completion of crash recovery).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2015-03-23 18:47:52 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>--debug</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Print verbose debugging output that is mostly useful for developers
|
2017-10-09 03:44:17 +02:00
|
|
|
debugging <application>pg_rewind</application>.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2020-06-07 14:07:33 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>--no-ensure-shutdown</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<application>pg_rewind</application> requires that the target server
|
|
|
|
is cleanly shut down before rewinding. By default, if the target server
|
|
|
|
is not shut down cleanly, <application>pg_rewind</application> starts
|
|
|
|
the target server in single-user mode to complete crash recovery first,
|
|
|
|
and stops it.
|
|
|
|
By passing this option, <application>pg_rewind</application> skips
|
|
|
|
this and errors out immediately if the server is not cleanly shut
|
|
|
|
down. Users are expected to handle the situation themselves in that
|
|
|
|
case.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Allow using syncfs() in frontend utilities.
This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file. In
many cases, using syncfs() is much faster.
As with recovery_init_sync_method, this new option comes with some
caveats. The descriptions of these caveats have been moved to a
new appendix section in the documentation.
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/20210930004340.GM831%40telsasoft.com
2023-09-07 01:27:16 +02:00
|
|
|
<varlistentry>
|
2023-10-04 21:40:50 +02:00
|
|
|
<term><option>--sync-method=<replaceable class="parameter">method</replaceable></option></term>
|
Allow using syncfs() in frontend utilities.
This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file. In
many cases, using syncfs() is much faster.
As with recovery_init_sync_method, this new option comes with some
caveats. The descriptions of these caveats have been moved to a
new appendix section in the documentation.
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/20210930004340.GM831%40telsasoft.com
2023-09-07 01:27:16 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When set to <literal>fsync</literal>, which is the default,
|
|
|
|
<command>pg_rewind</command> will recursively open and synchronize all
|
|
|
|
files in the data directory. The search for files will follow symbolic
|
|
|
|
links for the WAL directory and each configured tablespace.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
On Linux, <literal>syncfs</literal> may be used instead to ask the
|
|
|
|
operating system to synchronize the whole file systems that contain the
|
|
|
|
data directory, the WAL files, and each tablespace. See
|
|
|
|
<xref linkend="syncfs"/> for more information about using
|
|
|
|
<function>syncfs()</function>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This option has no effect when <option>--no-sync</option> is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2015-03-23 18:47:52 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-V</option></term>
|
|
|
|
<term><option>--version</option></term>
|
2015-09-18 02:56:58 +02:00
|
|
|
<listitem><para>Display version information, then exit.</para></listitem>
|
2015-03-23 18:47:52 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>-?</option></term>
|
|
|
|
<term><option>--help</option></term>
|
2015-09-18 02:56:58 +02:00
|
|
|
<listitem><para>Show help, then exit.</para></listitem>
|
2015-03-23 18:47:52 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Environment</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When <option>--source-server</option> option is used,
|
2015-03-23 18:47:52 +01:00
|
|
|
<application>pg_rewind</application> also uses the environment variables
|
2017-11-23 15:39:47 +01:00
|
|
|
supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>).
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
The environment variable <envar>PG_COLOR</envar> specifies whether to use
|
2020-03-09 02:53:22 +01:00
|
|
|
color in diagnostic messages. Possible values are
|
|
|
|
<literal>always</literal>, <literal>auto</literal> and
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
<literal>never</literal>.
|
|
|
|
</para>
|
2015-03-23 18:47:52 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
2019-04-05 03:37:59 +02:00
|
|
|
<para>
|
|
|
|
When executing <application>pg_rewind</application> using an online
|
|
|
|
cluster as source, a role having sufficient permissions to execute the
|
|
|
|
functions used by <application>pg_rewind</application> on the source
|
|
|
|
cluster can be used instead of a superuser. Here is how to create such
|
|
|
|
a role, named <literal>rewind_user</literal> here:
|
|
|
|
<programlisting>
|
|
|
|
CREATE USER rewind_user LOGIN;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text) TO rewind_user;
|
|
|
|
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
|
2019-04-08 22:27:35 +02:00
|
|
|
</programlisting>
|
2019-04-05 03:37:59 +02:00
|
|
|
</para>
|
|
|
|
|
2015-03-23 18:47:52 +01:00
|
|
|
<refsect2>
|
2019-09-08 10:26:35 +02:00
|
|
|
<title>How It Works</title>
|
2015-03-23 18:47:52 +01:00
|
|
|
|
|
|
|
<para>
|
2016-08-01 18:52:22 +02:00
|
|
|
The basic idea is to copy all file system-level changes from the source
|
|
|
|
cluster to the target cluster:
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<procedure>
|
|
|
|
<step>
|
|
|
|
<para>
|
2016-08-01 18:52:22 +02:00
|
|
|
Scan the WAL log of the target cluster, starting from the last
|
|
|
|
checkpoint before the point where the source cluster's timeline
|
|
|
|
history forked off from the target cluster. For each WAL record,
|
|
|
|
record each data block that was touched. This yields a list of all
|
|
|
|
the data blocks that were changed in the target cluster, after the
|
2020-04-01 03:57:03 +02:00
|
|
|
source cluster forked off. If some of the WAL files are no longer
|
|
|
|
available, try re-running <application>pg_rewind</application> with
|
|
|
|
the <option>-c</option> option to search for the missing files in
|
|
|
|
the WAL archive.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</step>
|
|
|
|
<step>
|
|
|
|
<para>
|
2016-08-01 18:52:22 +02:00
|
|
|
Copy all those changed blocks from the source cluster to
|
|
|
|
the target cluster, either using direct file system access
|
2017-10-09 03:44:17 +02:00
|
|
|
(<option>--source-pgdata</option>) or SQL (<option>--source-server</option>).
|
2020-05-01 10:40:41 +02:00
|
|
|
Relation files are now in a state equivalent to the moment of the last
|
|
|
|
completed checkpoint prior to the point at which the WAL timelines of the
|
|
|
|
source and target diverged plus the current state on the source of any
|
|
|
|
blocks changed on the target after that divergence.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</step>
|
|
|
|
<step>
|
|
|
|
<para>
|
2020-05-01 10:40:41 +02:00
|
|
|
Copy all other files, including new relation files, WAL segments,
|
|
|
|
<filename>pg_xact</filename>, and configuration files from the source
|
|
|
|
cluster to the target cluster. Similarly to base backups, the contents
|
|
|
|
of the directories <filename>pg_dynshmem/</filename>,
|
2018-03-28 21:56:52 +02:00
|
|
|
<filename>pg_notify/</filename>, <filename>pg_replslot/</filename>,
|
|
|
|
<filename>pg_serial/</filename>, <filename>pg_snapshots/</filename>,
|
2020-05-01 10:40:41 +02:00
|
|
|
<filename>pg_stat_tmp/</filename>, and <filename>pg_subtrans/</filename>
|
|
|
|
are omitted from the data copied from the source cluster. The files
|
2018-03-28 21:56:52 +02:00
|
|
|
<filename>backup_label</filename>,
|
|
|
|
<filename>tablespace_map</filename>,
|
|
|
|
<filename>pg_internal.init</filename>,
|
2020-05-01 10:40:41 +02:00
|
|
|
<filename>postmaster.opts</filename>, and
|
|
|
|
<filename>postmaster.pid</filename>, as well as any file or directory
|
|
|
|
beginning with <filename>pgsql_tmp</filename>, are omitted.
|
|
|
|
</para>
|
|
|
|
</step>
|
|
|
|
<step>
|
|
|
|
<para>
|
|
|
|
Create a <filename>backup_label</filename> file to begin WAL replay at
|
|
|
|
the checkpoint created at failover and configure the
|
|
|
|
<filename>pg_control</filename> file with a minimum consistency LSN
|
|
|
|
defined as the result of <literal>pg_current_wal_insert_lsn()</literal>
|
|
|
|
when rewinding from a live source or the last checkpoint LSN when
|
|
|
|
rewinding from a stopped source.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</step>
|
|
|
|
<step>
|
|
|
|
<para>
|
2020-05-01 10:40:41 +02:00
|
|
|
When starting the target, <productname>PostgreSQL</productname> replays
|
|
|
|
all the required WAL, resulting in a data directory in a consistent
|
|
|
|
state.
|
2015-03-23 18:47:52 +01:00
|
|
|
</para>
|
|
|
|
</step>
|
|
|
|
</procedure>
|
|
|
|
</refsect2>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|