4
Cold Backup
Server is off
if the checkpoint is completed, you can just copy the files
the backup can be deployed on a different server, regardless of the PGDATA
location
+ simplicity
− requires service interruption
File system snapshot
Similar to an unexpected shutdown: recovery required on startup, but the
backup has all necessary WAL files
all data, including tablespaces, must be captured in a single snapshot
+ no server downtime required
− file systems with snapshot support are generally slower
A cold backup is made when the data on disk is in a consistent state: that is,
all pages are stored on disk and are up to date.
Restoring from such a backup is straightforward: just extract the files, start
the server, and it's good to go.
But to create such a backup, you must perform a checkpoint and a clean
server shutdown first.
This is a major drawback: shutdowns can take a while, especially with large
volumes of data.
The downtime can be reduced by running rsync (or a similar tool)
beforehand while the server is still running. After the server is shut down,
rsync will only need to copy the changes (which should be relatively few).
However, some downtime is still unavoidable.
Another option is to make an inconsistent copy, which will include pages
saved at different times. This inconsistency is inevitable when the server is
shut down incorrectly or when creating a snapshot of the file system. In the
latter case, all cluster files should fall into one snapshot. This may not be
possible if the files are on different file systems.
When recovering from inconsistent data, the server will need to restore
consistency at startup. This is the standard automatic crash recovery
procedure. This isn't a problem since the necessary WAL files are
guaranteed to be backed up, though the recovery process can take some
time.