3.10. Cloning and Synchronizing a Postgres Pro Instance #

pg_probackup3 can create a copy of a Postgres Pro instance directly, without using the backup catalog. To do this, you can run the catchup command. It can be useful in the following cases:

  • To add a new standby server.

    If the data directory of the destination instance is empty, the catchup command works similarly to the backup command in the PRO mode, but it can be faster if run in parallel mode.

    Note

    The catchup operations are currently only supported in the PRO mode and do not require direct access to PGDATA.

  • To have a fallen-behind standby server catch up with the primary.

    Under write-intensive load, replicas may fail to replay WAL fast enough to keep up with the primary and hence may lag behind. A usual solution to create a new replica and switch to it requires a lot of extra space and data transfer. The catchup command allows you to update an existing replica much faster by fetching differences from the primary.

catchup specifications and limitations:

  • The backup catalog is not required.

  • Copying external directories is not supported.

  • The remote mode is not supported.

  • DDL commands CREATE TABLESPACE/DROP TABLESPACE cannot be run simultaneously with catchup.

  • catchup takes configuration files, such as postgresql.conf, postgresql.auto.conf, or pg_hba.conf, from the source server and overwrites them on the target server. The --exclude-path option allows you to keep the configuration files intact.

To prepare for cloning/synchronizing a Postgres Pro instance, set up the source server as follows:

Before cloning/synchronizing a Postgres Pro instance, ensure that the source server is running and accepting connections. To clone/synchronize a Postgres Pro instance, on the server with the destination instance, run the catchup command as follows:

pg_probackup3 catchup -b catchup_mode --destination-pgdata=path_to_local_dir --stream [connection_options]

Where catchup_mode can take one of the following values:

  • FULL — creates a full copy of the Postgres Pro instance. The data directory of the destination instance must be empty for this mode.

  • DELTA — reads all data files in the data directory and creates an incremental copy for pages that have changed since the destination instance was shut down.

  • PTRACK — tracks page changes on the fly, only reads and copies pages that have changed since the point of divergence of the source and destination instances.

By specifying the --stream option, you can set the STREAM WAL delivery mode of copying, which will include all the necessary WAL files by streaming them from the server via replication protocol.

You can use connection_options to specify the connection to the source database cluster.

If the source database cluster contains tablespaces that must be located in a different directory, additionally specify the --tablespace-mapping option:

pg_probackup3 catchup -b catchup_mode --destination-pgdata=path_to_local_dir --stream --tablespace-mapping=OLDDIR=NEWDIR

To run the catchup command on parallel threads, specify the number of threads with the --threads or --num-write-threads and --num-validate-threads options:

pg_probackup3 catchup -b catchup_mode --destination-pgdata=path_to_local_dir --stream --threads=num_threads