PTRACK is a block-level incremental backup engine for Postgres Pro. If PTRACK is enabled, backup tools like pg_probackup can use its API to get information on the changed blocks on the fly when taking incremental backups. Copying only those blocks that have changed since the previous backup can significantly speed up the creation and minimize the size of backups.
PTRACK is designed to allow false positives, but to never allow false negatives: it means that all changes within the data directory except hint bits are guaranteed to be marked in the PTRACK map file, although some unchanged blocks might be included as well.
Once you complete Postgres Pro Standard installation, do the following:
Add ptrack to the
shared_preload_libraries parameter
in the postgresql.conf file:
shared_preload_libraries = 'ptrack'
Set ptrack.map_size parameter to a positive integer.
For optimal performance, it is recommended to set
ptrack.map_size to
, where
N / 1024N is the size of the
Postgres Pro cluster, in MB. If you set this
parameter to a lower value, PTRACK is more likely to map several blocks
together, which leads to false-positive results when tracking changed
blocks and increases the incremental backup size as unchanged blocks
can also be copied into the incremental backup.
Setting ptrack.map_size to a higher value does not
affect PTRACK operation, but keep in mind that you need up to
MB of
additional disk space since PTRACK uses two additional temporary files
to ensure durability. It is not recommended to set this parameter
to a value higher than 1GB.
ptrack.map_size * 3
Check the wal_level setting.
When using PTRACK, it is required to set the wal_level
parameter to replica or higher.
Otherwise, you can lose some tracked changes if crash-recovery occurs:
some commands do not write WAL at all if wal_level
is minimal, and PTRACK map files are
flushed to disk only at checkpoint time.
Restart the Postgres Pro Standard instance for the changes to take effect, and then create the PTRACK extension:
CREATE EXTENSION ptrack;
As a result, several PTRACK functions are created, which are required for accessing PTRACK data.
Once this setup is complete, PTRACK starts tracking all the page
changes in the Postgres Pro cluster and
creates a ptrack.map file that stores
the latest LSN values for these pages.
The ptrack.map_size parameter can only be set at
server start. If you change this parameter, the previously created
PTRACK map file is cleared, and tracking newly changed blocks starts
from scratch. To avoid losing recent changes, it is recommended to
retake a full backup after modifying this setting.
ptrack.map_size (integer)
Specifies the size of a PTRACK map file and the amount of shared memory allocated for this file, in MB. The PTRACK map file stores the latest LSN values for all pages of the Postgres Pro cluster that have changed since PTRACK was enabled. It is not recommended to set this parameter to a value higher than 1GB. The -1 value disables PTRACK, while the 0 value both disables PTRACK and cleans up all the related service files.
The ptrack.map_size parameter can only be set at
server start. If you change this parameter, the previously created
PTRACK map file is cleared, and tracking newly changed blocks starts
from scratch. To avoid losing recent changes, it is recommended to
retake a full backup after modifying this setting.
Default: -1
ptrack_init_lsn() returns pg_lsn
Returns the LSN of the last PTRACK map initialization.
ptrack_get_pagemapset(lsn pg_lsn) returns setof record
Returns a list of changed data files with bitmaps of changed blocks since the specified LSN.
For example:
SELECT * FROM ptrack_get_pagemapset('0/2000028');
path | pagemap
----------------------+--------------------------
global/2698 | \x0700000000000000000000
global/6000 | \x0100000000000000000000
global/3593 | \x0300000000000000000000
global/1232 | \x0700000000000000000000
global/1233 | \x0700000000000000000000
global/1214_vm | \x0300000000000000000000
global/2847 | \x0300000000000000000000
global/2396 | \x0300000000000000000000
base/1/3603 | \x0f00000000000000000000
base/1/3081 | \x0700000000000000000000
base/1/2652 | \x0700000000000000000000
base/1/4152 | \x0300000000000000000000
ptrack_version() returns text
Returns PTRACK version.