This user guide is intended to be followed sequentially from beginning to end — each section depends on the last. For example the Backup section relies on setup that is performed in the Quick Start section. Once you have
Although the examples are targeted at Ubuntu and
A somewhat novel approach is taken to documentation in this user guide. Each command is run on a virtual machine when the documentation is built from the XML source. This means you can have a high confidence that the commands work correctly in the order presented. Output is captured and displayed below the command when appropriate. If the output is not included it is because it was deemed not relevant or was considered a distraction from the narrative.
All commands are intended to be run as an unprivileged user that has sudo privileges for both the
The following concepts are defined as they are relevant to
A backup is a consistent copy of a database cluster that can be restored to recover from a hardware failure, to perform Point-In-Time Recovery, or to bring up a new replica.
Full Backup:
Differential Backup:
Incremental Backup:
A restore is the act of copying a backup to a system where it will be started as a live database cluster. A restore requires the backup files and one or more WAL segments in order to work correctly.
WAL is the mechanism by which
WAL is conceptually infinite but in practice is broken up into individual 16MB files called segments. WAL segments follow the naming convention
A valid backup will always include at least one WAL segment even if no writes were made to the database between backups.
No Debian/Ubuntu packages are currently available for
The Quick Start section will cover basic configuration of
You'll need to create a demo cluster to run the example commands in this user guide. This step is optional, but you may need to adjust commands in the user guide to work with your environment if you choose not to create the demo cluster.
Demo describes the purpose of this cluster accurately so that will also make a good stanza name.
By default Ubuntu stores clusters in
For this simple configuration the repository will be stored on the same host as the
The repository path must be configured so
Backing up a running
The
The
To perform a backup of the
By default
The
This time there was no warning because a full backup already existed. Like incremental backups, differential backups must be based on a full backup. An incremental backup can be performed by running the
Use the
The oldest and newest backups are shown in the info output. The oldest backup will always be a full backup (indicated by an
More information about the
Backups can protect you from a number of disaster scenarios, the most common of which are hardware failure and data corruption. The easiest way to simulate data corruption is to remove an important
Starting the cluster without this important file will result in an error.
To restore a backup of the
This time the cluster started successfully since the
More information about the
The Backup section introduces additional
By default
By setting
Sometimes
Here an error in intentionally caused by removing repository permissions.
Even when the permissions are fixed
Enabling the
Now
Although useful this feature may not be appropriate when another third-party backup solution is being used to take online backups as
Note that
The Restore section introduces additional
The restore example in Quick Start performed default recovery, which is to play all the way to the end of the WAL stream. In the case of a hardware failure this is probably the most appropriate action but for data corruption scenarios (whether machine or human in origin) there is a better alternative called Point-in-Time Recovery (PITR).
PITR allows the WAL to be played from the last backup to a specified time, transaction id, or recovery point. For common recovery scenarios time-based recovery is arguably the most useful. A common recovery scenario is to restore a table or data was accidentally dropped or deleted. Recovering a dropped table is more dramatic so that's the example given here but deleted data would be recovered in exactly the same way.
It is important to represent the time as reckoned by
Now that the time has been recorded the table is dropped. In practice finding the exact time that the table was dropped is a lot harder than in this example. It may not be possible to find the exact time, but some forensic work should be able to get you close.
Now the restore can be performed with time-based recovery to
The
The
This example was rigged to give the correct result. If a backup after the required time is chosen then
Now take a new backup and attempt the recovery from the new backup.
Looking at the log output it's not obvious that recovery failed to restore the table. The key is to look for the presence of the "recovery stopping before..." and "last completed transaction..." log messages. If they are not present then the recovery to the specified point-in-time was not successful.
Using an earlier backup will allow
Now the the log output will contain the expected "recovery stopping before..." and "last completed transaction..." messages showing that the recovery was successful.