- linkend="guc-archive-command"> by requiring it to keep track of
- successively archived, but different, copies of the same WAL file.
- The is only invoked on finished
- WAL segments that will not change anymore; and except in the case of
- retrying a failure, it will be called only once for any given file name.
+ If you are concerned about being able to recover right up to the
+ current instant, you may want to take additional steps to ensure that
+ the current, partially-filled WAL segment is also copied someplace.
+ This is particularly important if your server generates only little WAL
+ traffic (or has slack periods where it does so), since it could take a
+ long time before a WAL segment file is completely filled and ready to
+ archive. One possible way to handle this is to set up a
+
cron> job that periodically (once a minute, perhaps)
+ identifies the current WAL segment file and saves it someplace safe.
+ Then the combination of the archived WAL segments and the saved current
+ segment will be enough to ensure you can always restore to within a
+ minute of current time. This behavior is not presently built into
+
PostgreSQL> because we did not want to complicate the
+ definition of the by requiring it
+ to keep track of successively archived, but different, copies of the
+ same WAL file. The is only
+ invoked on completed WAL segments. Except in the case of retrying a
+ failure, it will be called only once for any given file name.
remember the original full path (%p>) but it is necessary to
remember the file name (%f>).
+
+ Note that although WAL archiving will allow you to restore any
+ modifications made to the data in your
PostgreSQL> database
+ it will not restore changes made to configuration files (that is,
+ postgresql.conf>, pg_hba.conf> and
+ pg_ident.conf>) after the initial base backup.
+
SELECT pg_start_backup('label');
where label> is any string you want to use to uniquely
- identify this backup operation. (One good practice is to use the
- full path where you intend to put the backup dump file.) It does
- not matter which database within the cluster you connect to to issue
- this command. You can ignore the result returned by the function;
+ identify this backup operation. pg_start_backup> creates
+ a backup label> file, called backup_label>,
+ in the cluster directory with information about your backup.
+ One good practice is to use the full path where you intend to put the
+ backup dump file as.
+
+
+ It does not matter which database within the cluster you connect to to
+ issue this command. You can ignore the result returned by the function;
but if it reports an error, deal with that before proceeding.
nor between the end of the backup and pg_stop_backup>; a
few minutes' delay won't hurt anything. You
must however be quite sure that these operations are carried out in
- sequence and don't overlap.
+ sequence and do not overlap.
Since you have to keep around all the archived WAL files back to your
- last full dump, your interval between full dumps would usually be chosen
- based on how much storage you want to expend on archived WAL files.
- You should also consider how long you are prepared to spend recovering,
- if recovery should be necessary --- the system will have to replay all
- those segments, and that could take awhile if it's been a long time
- since the full dump.
+ last base backup, the interval between base backups should usually be
+ chosen based on how much storage you want to expend on archived WAL
+ files. You should also consider how long you are prepared to spend
+ recovering, if recovery should be necessary --- the system will have to
+ replay all those WAL segments, and that could take awhile if it has
+ been a long time since the last base backup.
It's also worth noting that the pg_start_backup> function
- makes a file named <literal>backup_label> in the database cluster
+ makes a file named <filename>backup_label> in the database cluster
directory, which is then removed again by pg_stop_backup>.
This file will of course be archived as a part of your backup dump file.
The backup label file includes the label string you gave to
It is also possible to make a backup dump while the postmaster is
- stopped. In this case, obviously you can't use
+ stopped. In this case, you obviously cannot use
pg_start_backup> or pg_stop_backup>, and
you will therefore be left to your own devices to keep track of which
backup dump is which and how far back the associated WAL files go.
- It's generally better to follow the on-line backup procedure above.
+ It is generally better to follow the on-line backup procedure above.
- Stop the postmaster, if it's running, and clean out all existing files
- under the cluster data directory and under the root directories of any
- tablespaces you are using.
- (If there are recent, unarchived WAL segment files in
- pg_xlog/> that you want to use during restore, move these aside
- instead of removing them.)
+ Stop the postmaster, if it's running. If you have the space to do so,
+ copy the cluster data directory and any tablespaces to a temporary
+ location so that you can reference them later. Note that this will
+ require that you have enough free space on your system to hold two
+ copies of your existing database. If you do not have enough space,
+ you need at the least to backup the pg_xlog> directory in
+ the cluster data directory as it may contain logs which were not archived
+ before the system went down.
+
+
+ Next, clean out all existing files under the cluster data directory and
+ under the root directories of any tablespaces you are using.
- If you had unarchived WAL segment files that you saved aside in step 1,
- copy them into pg_xlog/>. (It's best to copy them, not move
- them back in, so that you still have the unmodified files if the worst
- happens and you have to start over.)
+ If you had unarchived WAL segment files that you saved in step 1,
+ copy them into pg_xlog/>. (It is best to copy them,
+ not move them, so that you still have the unmodified files if a
+ problem occurs and you have to start over.)
Create a recovery command file recovery.conf> in the cluster
- data directory, as discussed below. You may also want to temporarily
- modify pg_hba.conf> to prevent ordinary users from connecting
- until you are sure the recovery has worked.
+ data directory (see ). You may
+ also want to temporarily modify pg_hba.conf> to prevent
+ ordinary users from connecting until you are sure the recovery has worked.
- The key part of all this is to set up a recovery command file
- that describes how you want to recover and how far the recovery
- should run. You can use recovery.conf.sample> (normally
+ The key part of all this is to set up a recovery command file that
+ describes how you want to recover and how far the recovery should
+ run. You can use recovery.conf.sample> (normally
installed in the installation share/> directory) as a
prototype. The one thing that you absolutely must specify in
- recovery.conf> is the <literal>restore_command>,
- which tells how to get back archived WAL file segments. Like
- the archive_command>, this is a shell command string.
- It may contain %f>,
- which is replaced by the name of the desired log file, and %p>,
+ recovery.conf> is the <varname>restore_command>,
+ which tells
PostgreSQL> how to get back archived
+ WAL file segments. Like the archive_command>, this is
+ a shell command string. It may contain %f>, which is
+ replaced by the name of the desired log file, and %p>,
which is replaced by the absolute path to copy the log file to.
Write %%> if you need to embed an actual %>
- character in the command. The simplest useful command is something
- like
+ character in the command. The simplest useful command is
+ something like
restore_command = 'cp /mnt/server/archivedir/%f %p'
Normally, recovery will proceed through all available WAL segments,
- thereby restoring the database to current time (or as close as we can
- get given the available WAL segments). But if you want to recover to
- some previous point in time (say, right before the junior DBA dropped your
- main transaction table), just specify the required stopping point in
- recovery.conf>. You can specify the stop point, known as the
- recovery target>, either by date/time or by completion of a
- specific transaction ID. As of this writing
- only the date/time option is very usable, since there are no tools
- to help you identify with any accuracy which transaction ID to use.
-
- Note that the stop point must be after the ending time of the backup
- (ie, the time of pg_stop_backup>). You cannot use a base
- backup to recover to a time when that backup was still going on. (To
- recover to such a time, you must go back to your previous base backup
- and roll forward from there.)
+ thereby restoring the database to the current point in time (or as
+ close as we can get given the available WAL segments). But if you want
+ to recover to some previous point in time (say, right before the junior
+ DBA dropped your main transaction table), just specify the required
+ stopping point in recovery.conf>. You can specify the stop
+ point, known as the recovery target>, either by date/time or
+ by completion of a specific transaction ID. As of this writing only
+ the date/time option is very usable, since there are no tools to help
+ you identify with any accuracy which transaction ID to use.
-
+
+ The stop point must be after the ending time of the base backup (the
+ time of pg_stop_backup>). You cannot use a base backup
+ to recover to a time when that backup was still going on. (To
+ recover to such a time, you must go back to your previous base backup
+ and roll forward from there.)
+
+
+
+
Recovery Settings
- These settings can only be made in the
- recovery.conf file, and apply only for the
- duration of the recovery. They must be reset for any subsequent
- recovery you wish to perform. They cannot be changed once recovery
- has begun.
-
+ These settings can only be made in the recovery.conf>
+ file, and apply only for the duration of the recovery. They must be
+ reset for any subsequent recovery you wish to perform. They cannot be
+ changed once recovery has begun.
+
in the command.
- It is important for the command to return a zero exit status only if
- it succeeds. The command will> be asked for file names
- that are not present in the archive;
- it must return nonzero when so asked.
- Examples:
+ It is important for the command to return a zero exit status only
+ if it succeeds. The command will> be asked for file
+ names that are not present in the archive; it must return nonzero
+ when so asked. Examples:
restore_command = 'cp /mnt/server/archivedir/%f "%p"'
restore_command = 'copy /mnt/server/archivedir/%f "%p"' # Windows
Tuesday evening, and are up and running. In this> history of
the database universe, you never dropped the table at all. But suppose
you later realize this wasn't such a great idea after all, and would like
- to return to some later point in the original history? You won't be able
+ to return to some later point in the original history. You won't be able
to if, while your database was up-and-running, it overwrote some of the
sequence of WAL segment files that led up to the time you now wish you
could get back to. So you really want to distinguish the series of
Operations on non-btree indexes (hash, R-tree, and GiST indexes) are
not presently WAL-logged, so replay will not update these index types.
- The recommended workaround, if you use any non-btree indexes, is to
- manually REINDEX> each such index after completing a
- recovery operation.
+ The recommended workaround is to manually REINDEX> each
+ such index after completing a recovery operation.