@@ -1486,143 +1486,6 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
14861486 </para>
14871487 </sect1>
14881488
1489- <sect1 id="log-shipping-alternative">
1490- <title>Alternative Method for Log Shipping</title>
1491-
1492- <para>
1493- An alternative to the built-in standby mode described in the previous
1494- sections is to use a <varname>restore_command</varname> that polls the archive location.
1495- This was the only option available in versions 8.4 and below.
1496- </para>
1497-
1498- <para>
1499- Note that in this mode, the server will apply WAL one file at a
1500- time, so if you use the standby server for queries (see Hot Standby),
1501- there is a delay between an action in the primary and when the
1502- action becomes visible in the standby, corresponding to the time it takes
1503- to fill up the WAL file. <varname>archive_timeout</varname> can be used to make that delay
1504- shorter. Also note that you can't combine streaming replication with
1505- this method.
1506- </para>
1507-
1508- <para>
1509- The operations that occur on both primary and standby servers are
1510- normal continuous archiving and recovery tasks. The only point of
1511- contact between the two database servers is the archive of WAL files
1512- that both share: primary writing to the archive, standby reading from
1513- the archive. Care must be taken to ensure that WAL archives from separate
1514- primary servers do not become mixed together or confused. The archive
1515- need not be large if it is only required for standby operation.
1516- </para>
1517-
1518- <para>
1519- The magic that makes the two loosely coupled servers work together is
1520- simply a <varname>restore_command</varname> used on the standby that,
1521- when asked for the next WAL file, waits for it to become available from
1522- the primary. Normal recovery
1523- processing would request a file from the WAL archive, reporting failure
1524- if the file was unavailable. For standby processing it is normal for
1525- the next WAL file to be unavailable, so the standby must wait for
1526- it to appear. For files ending in
1527- <literal>.history</literal> there is no need to wait, and a non-zero return
1528- code must be returned. A waiting <varname>restore_command</varname> can be
1529- written as a custom script that loops after polling for the existence of
1530- the next WAL file. There must also be some way to trigger failover, which
1531- should interrupt the <varname>restore_command</varname>, break the loop and
1532- return a file-not-found error to the standby server. This ends recovery
1533- and the standby will then come up as a normal server.
1534- </para>
1535-
1536- <para>
1537- Pseudocode for a suitable <varname>restore_command</varname> is:
1538- <programlisting>
1539- triggered = false;
1540- while (!NextWALFileReady() && !triggered)
1541- {
1542- sleep(100000L); /* wait for ~0.1 sec */
1543- if (CheckForExternalTrigger())
1544- triggered = true;
1545- }
1546- if (!triggered)
1547- CopyWALFileForRecovery();
1548- </programlisting>
1549- </para>
1550-
1551- <para>
1552- The method for triggering failover is an important part of planning
1553- and design. One potential option is the <varname>restore_command</varname>
1554- command. It is executed once for each WAL file, but the process
1555- running the <varname>restore_command</varname> is created and dies for
1556- each file, so there is no daemon or server process, and
1557- signals or a signal handler cannot be used. Therefore, the
1558- <varname>restore_command</varname> is not suitable to trigger failover.
1559- It is possible to use a simple timeout facility, especially if
1560- used in conjunction with a known <varname>archive_timeout</varname>
1561- setting on the primary. However, this is somewhat error prone
1562- since a network problem or busy primary server might be sufficient
1563- to initiate failover. A notification mechanism such as the explicit
1564- creation of a trigger file is ideal, if this can be arranged.
1565- </para>
1566-
1567- <sect2 id="warm-standby-config">
1568- <title>Implementation</title>
1569-
1570- <para>
1571- The short procedure for configuring a standby server using this alternative
1572- method is as follows. For
1573- full details of each step, refer to previous sections as noted.
1574- <orderedlist>
1575- <listitem>
1576- <para>
1577- Set up primary and standby systems as nearly identical as
1578- possible, including two identical copies of
1579- <productname>PostgreSQL</productname> at the same release level.
1580- </para>
1581- </listitem>
1582- <listitem>
1583- <para>
1584- Set up continuous archiving from the primary to a WAL archive
1585- directory on the standby server. Ensure that
1586- <xref linkend="guc-archive-mode"/>,
1587- <xref linkend="guc-archive-command"/> and
1588- <xref linkend="guc-archive-timeout"/>
1589- are set appropriately on the primary
1590- (see <xref linkend="backup-archiving-wal"/>).
1591- </para>
1592- </listitem>
1593- <listitem>
1594- <para>
1595- Make a base backup of the primary server (see <xref
1596- linkend="backup-base-backup"/>), and load this data onto the standby.
1597- </para>
1598- </listitem>
1599- <listitem>
1600- <para>
1601- Begin recovery on the standby server from the local WAL
1602- archive, using <varname>restore_command</varname> that waits
1603- as described previously (see <xref linkend="backup-pitr-recovery"/>).
1604- </para>
1605- </listitem>
1606- </orderedlist>
1607- </para>
1608-
1609- <para>
1610- Recovery treats the WAL archive as read-only, so once a WAL file has
1611- been copied to the standby system it can be copied to tape at the same
1612- time as it is being read by the standby database server.
1613- Thus, running a standby server for high availability can be performed at
1614- the same time as files are stored for longer term disaster recovery
1615- purposes.
1616- </para>
1617-
1618- <para>
1619- For testing purposes, it is possible to run both primary and standby
1620- servers on the same system. This does not provide any worthwhile
1621- improvement in server robustness, nor would it be described as HA.
1622- </para>
1623- </sect2>
1624- </sect1>
1625-
16261489 <sect1 id="hot-standby">
16271490 <title>Hot Standby</title>
16281491
0 commit comments