PTRACK is designed to track page changes in Postgres Pro on the fly. If page tracking is enabled, applications can use PTRACK API to get information on the changed blocks. For example, advanced backup tools like pg_probackup can take incremental backups by copying only those blocks that have changed since the previous backup, which can significantly speed up the creation and minimize the size of incremental backups.
Once you complete Postgres Pro Standard installation, do the following:
Create the PTRACK extension.
CREATE EXTENSION ptrack;
As a result, several PTRACK functions are created, which are required for accessing PTRACK data.
Check the wal_level setting.
When using PTRACK, it is required to set the wal_level
parameter to replica or higher.
Set ptrack_map_size parameter to a positive integer and restart the server.
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. The maximum allowed value is 1024.
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.
If you later change the ptrack_map_size
parameter, the previously created PTRACK map file is cleared,
and tracking newly changed blocks starts from scratch.
pg_ptrack_control_lsn() returns pg_lsn
Returns the LSN of the last PTRACK map initialization.
pg_ptrack_get_block(tablespace_oid oid, db_oid oid, relfilenode oid, blockno bigint) returns record
Reads the specified block of the specified relation in the specified tablespace into buffer cache and returns its copy as a bytea value.
pg_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 pg_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.