Rate This Document
Findability
Accuracy
Completeness
Readability

Performing a Full Backup of an x86 Node

Use the pg_basebackup tool to perform a full backup of PostgreSQL with either of the following methods: Pull the backup of the primary database to the secondary database, or create a backup package on the primary database and transfer it to the secondary database. Each method has its own advantages and application scenarios. Select a suitable method appropriate to your services.

Before the primary/secondary switchover, the primary database in this section refers to the x86 primary database. After the primary/secondary switchover, the primary database refers to the new Kunpeng primary database.

Method 1: Directly obtain the backup of the primary database on the secondary database.

  1. Install PostgreSQL 13.2 on the secondary database server. For details, see (Optional) Installing PostgreSQL.
  2. Switch to user postgres.
    su - postgres
  3. Run the backup command on the secondary database server to obtain data from the primary database.
    /usr/local/pgsql-13.2/bin/pg_basebackup -D /data/pg-13.2/data -h IP address of the primary database server -p Listening port number used by the primary database service -U backup -X stream -P

    Enter the password. The system starts to back up data of the primary database across hosts in stream mode.

  4. Modify the permission on the data directory of the secondary database to ensure security.
    chmod -R 700 /data/pg-13.2/data
    ll /data/pg-13.2/data

  5. Configure and start the secondary database.

    After the secondary database file is prepared, configure the secondary database node, and then start the database. Otherwise, the log sequence number (LSN) of the secondary database gets greater than that of the primary database or fork occurs, causing a replication failure.

Method 2: Create a backup package on the primary database and transfer it to the secondary database.

  1. On the primary database server, run pg_basebackup to generate a full backup and compress it.

    The previous step requires that the user has the write permission on the /data/pg-13.2 directory.

    In this example, create the data_bak directory in /data/pg-13.2 as the root user, run pg_basebackup to create a compressed package for the secondary database, and save the package to the /data/pg-13.2/data_bak directory.
    mkdir -p /data/pg-13.2/data_bak
    /usr/local/pgsql-13.2/bin/pg_basebackup -h 127.0.0.1 -p5432 -U backup -D /data/pg-13.2/data_bak -Xs -F t -z -v -P
    ll /data/pg-13.2/data_bak

  2. Run the following command on the primary database server to transfer the backup file from the primary database server to the secondary database server:
    scp -r /data/pg-13.2/data_bak root@IP address of the secondary database server:/data/pg-13.2/

    Modify parameters according to the parameter description down below and the actual situation in your case.

    • /data/pg-13.2/data_bak is the backup directory.
    • root is the user name of the secondary database server.
  3. Install PostgreSQL 13.2 on the secondary database server. For details, see (Optional) Installing PostgreSQL.
  4. Restore the backup data on the secondary database server.
    Decompress base.tar.gz to the specified secondary database data directory /data/pg-13.2/data, decompress pg_wal.tar.gz to the temporary directory /data/pg-13.2/archive, and change the owners and permissions of the files.
    tar -zxf /data/pg-13.2/data_bak/base.tar.gz -C /data/pg-13.2/data
    chown -R postgres:postgres /data/pg-13.2/data
    chmod -R 700 /data/pg-13.2/data
    ll /data/pg-13.2/data
    tar -zxf /data/pg-13.2/data_bak/pg_wal.tar.gz -C /data/pg-13.2/archive
    chown -R postgres:postgres /data/pg-13.2/archive
    chmod -R 700 /data/pg-13.2/archive
    ll /data/pg-13.2/archive

  5. Configure and start the secondary database.

    After the secondary database file is prepared, configure the secondary database node, and then start the database. Otherwise, the LSN of the secondary database gets greater than that of the primary database or fork occurs, causing a replication failure.