Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6559c4a

Browse files
committed
Add additional PITR documentation.
Simon Riggs
1 parentbb0e301 commit6559c4a

File tree

1 file changed

+119
-11
lines changed

1 file changed

+119
-11
lines changed

‎doc/src/sgml/backup.sgml

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.108 2007/11/2815:42:30 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.109 2007/11/2822:35:54 momjian Exp $ -->
22

33
<chapter id="backup">
44
<title>Backup and Restore</title>
@@ -641,10 +641,22 @@ archive_command = 'test ! -f .../%f &amp;&amp; cp %p .../%f'
641641
<para>
642642
Also, you can force a segment switch manually with
643643
<function>pg_switch_xlog</>, if you want to ensure that a
644-
just-finished transaction is archivedimmediately. Other utility
644+
just-finished transaction is archivedas soon as possible. Other utility
645645
functions related to WAL management are listed in <xref
646646
linkend="functions-admin-backup-table">.
647647
</para>
648+
649+
<para>
650+
When <varname>archive_mode</> is <literal>off</> some SQL commands
651+
are optimized to avoid WAL logging, as described in <xref
652+
linkend="populate-pitr">. If archiving were turned on during execution
653+
of one of these statements, WAL would not contain enough information
654+
for archive recovery. (Crash recovery is unaffected.) For
655+
this reason, <varname>archive_mode</> can only be changed at server
656+
start. (<varname>archive_command</> can be changed with a
657+
configuration file reload, and setting it to <literal>''</> does
658+
prevent archiving.)
659+
</para>
648660
</sect2>
649661

650662
<sect2 id="backup-base-backup">
@@ -973,14 +985,24 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
973985
<para>
974986
Normally, recovery will proceed through all available WAL segments,
975987
thereby restoring the database to the current point in time (or as
976-
close as we can get given the available WAL segments). But if you want
977-
to recover to some previous point in time (say, right before the junior
978-
DBA dropped your main transaction table), just specify the required
979-
stopping point in <filename>recovery.conf</>. You can specify the stop
980-
point, known as the <quote>recovery target</>, either by date/time or
981-
by completion of a specific transaction ID. As of this writing only
982-
the date/time option is very usable, since there are no tools to help
983-
you identify with any accuracy which transaction ID to use.
988+
close as we can get given the available WAL segments). So a normal
989+
recovery will end with a "file not found" message, the exact text
990+
of the error message depending upon your choice of
991+
<varname>restore_command</>. You may also see an error message
992+
at the start of recovery for a file named something like
993+
<filename>00000001.history</>. This is also normal and does not
994+
indicate a problem in simple recovery situations. See
995+
<xref linkend="backup-timelines"> for discussion.
996+
</para>
997+
998+
<para>
999+
If you want to recover to some previous point in time (say, right before
1000+
the junior DBA dropped your main transaction table), just specify the
1001+
required stopping point in <filename>recovery.conf</>. You can specify
1002+
the stop point, known as the <quote>recovery target</>, either by
1003+
date/time or by completion of a specific transaction ID. As of this
1004+
writing only the date/time option is very usable, since there are no tools
1005+
to help you identify with any accuracy which transaction ID to use.
9841006
</para>
9851007

9861008
<note>
@@ -1214,6 +1236,92 @@ restore_command = 'copy /mnt/server/archivedir/%f "%p"' # Windows
12141236
</para>
12151237
</sect2>
12161238

1239+
<sect2 id="backup-tips">
1240+
<title>Tips and Examples</title>
1241+
1242+
<para>
1243+
Some examples of configuring Continuous Archiving are given here.
1244+
</para>
1245+
1246+
<sect3 id="backup-standalone">
1247+
<title>Recovery Settings</title>
1248+
1249+
<para>
1250+
It is possible to use the existing backup facilities to produce
1251+
standalone hot backups. These are backups that cannot be used for
1252+
point-in-time recovery, yet are much faster to backup and restore
1253+
than <application>pg_dump</>.
1254+
</para>
1255+
1256+
<para>
1257+
To configure standalone backups you should use a switch file. If the
1258+
file exists then archives are made, otherwise archiving is ignored.
1259+
<programlisting>
1260+
archive_command = 'test -f /var/lib/pgsql/backup_in_progress &amp;&amp; cp -i %p /var/lib/pgsql/archive/%f &lt;/dev/null'
1261+
</programlisting>
1262+
Backup can then be taken using a script like the following:
1263+
<programlisting>
1264+
touch /var/lib/pgsql/backup_in_progress
1265+
psql -c "select pg_start_backup('hot_backup');"
1266+
tar -cvf /var/lib/pgsql/backup.tar /var/lib/pgsql/data/
1267+
psql -c "select pg_stop_backup();"
1268+
sleep 20
1269+
rm /var/lib/pgsql/backup_in_progress
1270+
tar -rvf /var/lib/pgsql/backup.tar /var/lib/pgsql/archive/
1271+
</programlisting>
1272+
The switch file <filename>/var/lib/pgsql/backup_in_progress</> is
1273+
created first, allowing archiving to start prior to the backup.
1274+
After the backup the switch file is removed. Archived WAL files are
1275+
then added to the backup so that both base backup and all required
1276+
WAL files are part of the same <application>tar</> file.
1277+
</para>
1278+
</sect3>
1279+
1280+
<sect3 id="backup-scripts">
1281+
<title><varname>archive_command</varname> scripts</title>
1282+
1283+
<para>
1284+
Many people choose to use scripts to define their
1285+
<varname>archive_command</varname>, so that their
1286+
<filename>postgresql.conf</> looks very simple:
1287+
<programlisting>
1288+
archive_command = 'local_backup_script.sh'
1289+
</programlisting>
1290+
This allows all complexity to be managed within the script, which
1291+
can be written in a popular scripting language such as
1292+
<application>bash</> or <application>perl</>. Statements echoed to
1293+
<literal>stderr</> will appear in the database server log, allowing
1294+
complex configurations to be easily diagnosed if they fail.
1295+
</para>
1296+
<para>
1297+
Example of how scripts might be used include:
1298+
<itemizedlist>
1299+
<listitem>
1300+
<para>
1301+
Copying data to a secure off-site data storage provider
1302+
</para>
1303+
</listitem>
1304+
<listitem>
1305+
<para>
1306+
Batching WAL files so they are transferred every three hours, rather than
1307+
one at a time as they fill
1308+
</para>
1309+
</listitem>
1310+
<listitem>
1311+
<para>
1312+
Interfacing with other backup and recovery software
1313+
</para>
1314+
</listitem>
1315+
<listitem>
1316+
<para>
1317+
Interfacing with monitoring software to report errors directly
1318+
</para>
1319+
</listitem>
1320+
</itemizedlist>
1321+
</para>
1322+
</sect3>
1323+
</sect2>
1324+
12171325
<sect2 id="continuous-archiving-caveats">
12181326
<title>Caveats</title>
12191327

@@ -1435,7 +1543,7 @@ restore_command = 'copy /mnt/server/archivedir/%f "%p"' # Windows
14351543
Pseudocode for a suitable <varname>restore_command</> is:
14361544
<programlisting>
14371545
triggered = false;
1438-
while (!NextWALFileReady() && !triggered)
1546+
while (!NextWALFileReady() &amp;&amp; !triggered)
14391547
{
14401548
sleep(100000L); /* wait for ~0.1 sec */
14411549
if (CheckForExternalTrigger())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp