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
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 1024. Even for Postgres Pro
clusters with ptrack.map_size * 3 MBN > 1 TB, it
makes sense to use a higher value only if the efficiency and sizes of backups
are more critical than the potential overhead of maintaining a large PTRACK map.
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(start_lsn pg_lsn) returns setof record
Returns a list of data files changed since the specified start_lsn
with the number and bitmap of changed pages for each file.
For example:
postgres=# SELECT * FROM ptrack_get_pagemapset('0/185C8C0');
path | pagecount | pagemap
---------------------+-----------+----------------------------------------
base/16384/1255 | 3 | \x001000000005000000000000
base/16384/2674 | 3 | \x0000000900010000000000000000
base/16384/2691 | 1 | \x00004000000000000000000000
base/16384/2608 | 1 | \x000000000000000400000000000000000000
base/16384/2690 | 1 | \x000400000000000000000000
ptrack_get_change_stat(start_lsn pg_lsn) returns
record
Returns the statistics of changes (number of files, number of changed pages and their total size in MB)
since the specified start_lsn.
For example:
postgres=# SELECT * FROM ptrack_get_change_stat('0/285C8C8');
files | pages | size, MB
-------+-------+------------------------
20 | 25 | 0.19531250000000000000
ptrack_version() returns text
Returns PTRACK version.