All Products
Search
Document Center

ApsaraDB RDS:Use pg_basebackup to create a full backup for an ApsaraDB RDS for PostgreSQL instance

Last Updated:Mar 28, 2026

Use the pg_basebackup utility to create a physical full backup of your ApsaraDB RDS for PostgreSQL instance and export the backup files to your local machine or ECS instance.

Prerequisites

Before you begin, ensure that you have:

  • Added the IP address of your ECS instance or local machine to an IP address whitelist of the RDS instance. For more information, see Configure an IP address whitelist

  • Installed the same version of PostgreSQL on your ECS instance or local machine as the RDS instance runs

Background

pg_basebackup backs up all data in a PostgreSQL instance at the physical level. The resulting backup files support point-in-time recovery (PITR).

This topic uses CentOS 7 and PostgreSQL 15 as examples.

Usage notes

Back up an RDS PostgreSQL instance

  1. Log in to your ECS instance or local machine and run the following command:

    pg_basebackup -Ft -Pv -Xs -z -D <backupdir> -Z5 -h '<hostname>' -p <port> -U <username> -W

    The following table describes each parameter and flag in the command. For the full parameter reference, see pg_basebackup.

    Parameter or flagDescription
    -FtOutputs backup files in tar format.
    -PvShows progress and verbose output during the backup (-P for progress, -v for verbose).
    -XsStreams WAL (Write-Ahead Logging) files during the backup using the streaming replication protocol. This ensures the backup is consistent and ready for PITR.
    -zCompresses the output files with gzip.
    -Z5Sets the compression level to 5 (range: 1–9, where 9 is maximum compression).
    -WPrompts for a password.
    <backupdir>The local directory where backup files are saved. pg_basebackup creates this directory automatically. If the directory already exists and is not empty, the command fails with an error.
    <hostname>The endpoint of your RDS instance. If your ECS and RDS instances are in the same region under the same Alibaba Cloud account and share the same network type, use the internal endpoint. If both use VPC (Virtual Private Cloud), they must be in the same VPC. In other cases, use the public endpoint.
    Important

    To use a public endpoint, you must first apply for one. See Apply for or release a public endpoint.

    <port>The port of your RDS instance.
    <username>A username of your RDS instance.

    Example:

    pg_basebackup -Ft -Pv -Xs -z -D /pg15/backup1/ -Z5 -h pgm-bp****.pg.rds.aliyuncs.com -p 5432 -U test1 -W
  2. When the Password: prompt appears, enter the password for the username and press Enter.

  3. When base backup completed is displayed, the backup is complete.

What's next

To restore data from the backup files, follow the steps in Recovering using a continuous archive backup.