This topic describes how to use the pg_basebackup utility provided by open source PostgreSQL to create a full backup of your ApsaraDB RDS for PostgreSQL instance and export the backup files to your computer.

Prerequisites

Background information

pg_basebackup backs up all data of a PostgreSQL instance. The backup files can be used for point-in-time recovery. For more information, see pg_basebackup.

In this topic, CentOS 7 and PostgreSQL 12 are used as examples of how to create a full backup.

Precautions

We recommend that you use the privileged account of your RDS instance or an account that has the REPLICATION permission. Otherwise, you may have permission issues during creation.

Procedure

Note pg_basebackup cannot back up a single database or database object. For more information about how to back up a single database or database object, see Create a logical backup for an ApsaraDB RDS for PostgreSQL instance.
  1. Log on to your ECS instance or local host. Then, run the following command to back up a database from your RDS instance:
    pg_basebackup -Ft -Pv -Xs -z -D <backupdir> -Z5 -h '<hostname>' -p <port> -U <username> -W

    The following table describes parameters in this command. For more information, see pg_basebackup.

    Parameter Description
    backupdir The directory of backup files that are exported. The system automatically creates this directory. However, if this directory already exists and is not empty, the system reports an error.
    hostname The endpoint that you use to connect to your RDS instance.

    If your ECS and RDS instances are deployed in the same region under the same Alibaba Cloud account and have the same network type, we recommend that you use an internal endpoint. If both network types are VPC, the two instances must be in the same VPC.

    Use a public endpoint in other scenarios.

    Note If you want to use a public endpoint to access your RDS instance, make sure that you have applied for the public endpoint. For more information, see Apply for or release a public endpoint on an ApsaraDB RDS for PostgreSQL instance.
    port The port that you use to connect to your RDS instance.
    username A username of your RDS instance.

    Example:

    pg_basebackup -Ft -Pv -Xs -z -D /pg12/backup1/ -Z5 -h pgm-bpxxxxx.pg.rds.aliyuncs.com -p 1433 -U test1 -W
  2. When Password: appears, enter the password of the username of your RDS instance and press Enter.
    pg_basebackup

References

If you want to use the backup files to restore data, see Recovering Using a Continuous Archive Backup.