<application>pg_resetwal</application>. It would avoid
situations in which the target server might use WAL files from the source
server. If the target server has a standby, replication will break and a
fresh standby should be created.
</para>
<para>
Replication failures can occur if required WAL files are missing. To prevent
this, the source server must set
<xref linkend="guc-max-slot-wal-keep-size"/> to <literal>-1</literal> to
ensure that required WAL files are not prematurely removed.
</para>
</refsect2>
<refsect2>
<title>How It Works</title>
<para>
The basic idea is to have a replication start point from the source server
and set up a logical replication to start from this point:
</para>
<procedure>
<step>
<para>
Start the target server with the specified command-line options. If the
target server is already running,
<application>pg_createsubscriber</application> will terminate with an
error.
</para>
</step>
<step>
<para>
Check if the target server can be converted. There are also a few
checks on the source server. If any of the prerequisites are not met,
<application>pg_createsubscriber</application> will terminate with an
error.
</para>
</step>
<step>
<para>
Create a publication and replication slot for each specified database on
the source server. Each publication is created using <link
linkend="sql-createpublication-params-for-all-tables"><literal>FOR ALL
TABLES</literal></link>. If the <option>--publication</option> option
is not specified, the publication has the following name pattern:
<quote><literal>pg_createsubscriber_%u_%x</literal></quote> (parameter:
database <parameter>oid</parameter>, random <parameter>int</parameter>).
If the <option>--replication-slot</option> option is not specified, the
replication slot has the following name pattern:
<quote><literal>pg_createsubscriber_%u_%x</literal></quote> (parameters:
database <parameter>oid</parameter>, random <parameter>int</parameter>).
These replication slots will be used by the subscriptions in a future
step. The last replication slot LSN is used as a stopping point in the
<xref linkend="guc-recovery-target-lsn"/> parameter and by the
subscriptions as a replication start point. It guarantees that no
transaction will be lost.
</para>
</step>
<step>
<para>
Write recovery parameters into the target data directory and restart the
target server. It specifies an LSN (<xref
linkend="guc-recovery-target-lsn"/>) of the write-ahead log location up
to which recovery will proceed. It also specifies
<literal>promote</literal> as the action that the server should take
once the recovery target is reached. Additional <link
linkend="runtime-config-wal-recovery-target">recovery parameters</link>
are added to avoid unexpected behavior during the recovery process such
as end of the recovery as soon as a consistent state is reached (WAL
should be applied until the replication start location) and multiple
recovery targets that can cause a failure. This step finishes once the
server ends standby mode and is accepting read-write transactions.