- Notifications
You must be signed in to change notification settings - Fork86
Backup and recovery manager for PostgreSQL
License
postgrespro/pg_probackup
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
pg_probackup is a backup and recovery manager for PostgreSQL servers able to dodifferential and full backup as well as restore a cluster to astate defined by a given recovery target. It is designed to performperiodic backups of an existing PostgreSQL server, combined with WALarchives to provide a way to recover a server in case of failure ofserver because of a reason or another. Its differential backupfacility reduces the amount of data necessary to be taken betweentwo consecutive backups.
Main features:
- incremental backup from WAL and PTRACK
- backup from replica
- multithreaded backup and restore
- autonomous backup without archive command (will need slot replication)
Requirements:
=PostgreSQL 9.5
=gcc 4.4 or >=clang 3.6 or >= XLC 12.1
- pthread
The latest version of this software can be found on the project website athttps://github.com/postgrespro/pg_probackup. Original fork of pg_probackup can befound athttps://github.com/michaelpq/pg_arman.
Compiling pg_probackup requires a PostgreSQL installation to be in placeas well as a raw source tree. Pass the path to the PostgreSQL source treeto make, in the top_srcdir variable:
make USE_PGXS=1 top_srcdir=<path to PostgreSQL source tree>
In addition, you must have pg_config in $PATH.
The current version of pg_probackup is compatible with PostgreSQL 9.5 andupper versions.
pg_probackup has been tested on Linux and Unix-based platforms.
All the documentation you can findhere.
For tests you must have python 2.7 or python 3.3 and higher. Also good ideais make virtual enviroment byvirtualenv
.
First of all you need to installtestgres
python module which contains usefulfunctions to start postgres clusters and make queries:
pip install testgres
To run tests execute:
python -m unittest tests
from current (root of project) directory. If you want to run a specific postgres build thenyou should specify the path to your pg_config executable by setting PG_CONFIGenvironment variable:
export PG_CONFIG=/path/to/pg_config
Idea of block level incremental backup is that you may backup only blockschanged since last full backup. It gives two major benefits: taking backupsfaster and making backups smaller.
The major question here is how to get the list of changed blocks. Sinceeach block contains LSN number, changed blocks could be retrieved by full scanof all the blocks. But this approach consumes as much server IO as fullbackup.
This is why we implemented alternative approaches to retrievelist of changed blocks.
Scan WAL archive and extract changed blocks from it. However, shortcomingof these approach is requirement to have WAL archive.
Track bitmap of changes blocks inside PostgreSQL (ptrack). It introducessome overhead to PostgreSQL performance. On our experiments it appears to beless than 3%.
These two approaches were implemented in this fork of pg_probackup. The secondapproach requirespatch for PostgreSQL 9.6.2 orpatch for PostgreSQL 10 (master).
You need to apply ptrack patch toPostgreSQL 9.6.2orPostgreSQL 10 (master).Or you can build and installPGPRO9_5 or PGPRO9_6 branch of PostgreSQL.Note that PGPRO branches currently contain old version of ptrack.
You need to enable WAL archive by adding following lines to postgresql.conf:
wal_level = archivearchive_mode = onarchive_command = 'test ! -f /home/postgres/backup/wal/%f && cp %p /home/postgres/backup/wal/%f'
Example backup (assuming PostgreSQL is running):
# Init pg_aramn backup folderpg_probackup init -B /home/postgres/backup# Make full backup with 2 thread and verbose mode.pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b full -v -j 2# Show backups informationpg_probackup show -B /home/postgres/backup# Now you can insert or update some data in your database# Then start the incremental backup.pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b page -v -j 2# You should see that increment is really smallpg_probackup show -B /home/postgres/backup
For restore after remove your pgdata you can use:
pg_probackup restore -B /home/postgres/backup -D /home/postgres/pgdata -j 4 --verbose
The advantage of this approach is that you don't have to save WAL archive. You will need to enable ptrack in postgresql.conf (restart required).
ptrack_enable = on
Also, some WALs still need to be fetched in order to get consistent backup. pg_probackup can fetch them trough the streaming replication protocol. Thus, you also need toenable streaming replication connection.
Example backup (assuming PostgreSQL is running):
# Init pg_aramn backup folderpg_probackup init -B /home/postgres/backup# Make full backup with 2 thread and verbose mode.pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b full -v -j 2 --stream# Show backups informationpg_probackup show -B /home/postgres/backup# Now you can insert or update some data in your database# Then start the incremental backup.pg_probackup backup -B /home/postgres/backup -D /home/postgres/pgdata -b ptrack -v -j 2 --stream# You should see that increment is really smallpg_probackup show -B /home/postgres/backup
For restore after remove your pgdata you can use:
pg_probackup restore -B /home/postgres/backup -D /home/postgres/pgdata -j 4 --verbose --stream
pg_probackup can be distributed under the PostgreSQL license. See COPYRIGHTfile for more information. pg_arman is a fork of the existing projectpg_rman, initially created and maintained by NTT and Itagaki Takahiro.
About
Backup and recovery manager for PostgreSQL
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.