Relational Database ServiceRelational Database Service

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Help Center> Relational Database Service> User Guide> Working with RDS for PostgreSQL> Backups and Restorations> Restoring from Full Backup Files to a Self-Built PostgreSQL Database
Updated at: Apr 02, 2022 GMT+08:00

Restoring from Full Backup Files to a Self-Built PostgreSQL Database

You can download backup files by referring to Downloading a Full Backup File and restore data from them.

From July 21, 2020 to November 3, 2020, HUAWEI CLOUD has optimized the decompression of PostgreSQL backup packages. You can decompress PostgreSQL backup packages without using any decompression tools. Pay attention to the following when decompressing PostgreSQL backup packages:

  • For backup packages generated before July 21, 2020, you need to use a tool to decompress them by referring to Procedure (Decompression with Tools).
  • For backup packages generated after November 3, 2020, you can decompress them using commands by referring to Procedure (Decompression Using Commands) (Recommended).
  • Due to time differences, whether decompression using commands is available vary in different regions. For backup packages generated between July 21, 2020 and November 3, 2020, you can try to decompress them using commands first. If the decompression fails, then use a tool to decompress them.
  • If you have any questions on decompression using commands, submit a service ticket by choosing Service Tickets > Create Service Ticket on the management console.

Prerequisites

Decompression with tools:

  1. A tool for decompressing TAR files must be installed in a Unix-like system.
  2. Either python2.7 or python3 can be used.
  3. The following third-party packages need to be installed: lz4, gzip, and shutil.
  4. The version of the local database must be the same as that of the cloud database.
  5. Plugins of the same version as the cloud database are installed in the local database.

Procedure (Decompression Using Commands) (Recommended)

  1. Prepare a local directory for storing tablespaces.
  2. Stop the local database server.
  3. Store the following configuration files in the data directory of the local database to another directory: postgresql.conf, pg_hba.conf, and recovery.done.
  4. Clear the data directory of the local database.
  5. Run the following command to decompress backup files to the directory prepared in 1:

    tar -zxf src_file -C target_dir

    Variables in the command are described as follows:

    src_file: indicates the directory where PostgreSQL full backup files are stored.

    target_dir: indicates the directory to which data is restored and it has been prepared in step 1. The directory must be empty. If the directory does not exist, the system automatically creates it.

    The following directories are generated after the decompression:

    • base: stores full files.
    • pg_wal (if the PostgreSQL version is 9.x, the directory is pg_xlog): stores incremental files.
    • A number of tablespace directories named using digits (if the original backup contains tablespace files).

  6. Copy the files in 5 to a specified directory of the local database.

    1. Copy all the decompressed files in the base directory to the data directory of the local database, and then replace the three files in the data directory of the local database with the configuration files in step 3.
    2. Copy the files in the decompressed pg_wal directory (if the PostgreSQL version is 9.x, the directory is pg_xlog) to the pg_wal (or pg_xlog directory) under the data directory of the local database.
    3. If the original backup contains tablespace files, modify the corresponding tablespace soft links in data\tablespace_map.

  7. Reboot the database and wait until the database restoration is complete.

Procedure (Decompression with Tools)

  1. Prepare a local directory for storing tablespaces.
  2. Stop the local database server.
  3. Store the following configuration files in the data directory of the local database to another directory: postgresql.conf, pg_hba.conf, and recovery.done.
  4. Clear the data directory of the local database.
  5. Download the decompression tool.
  6. Run the following command to decompress backup files to the directory prepared in Step 1:

    python restore_obs_file.py src_file target_dir

    Variables in the command are described as follows:

    src_file: indicates the directory where PostgreSQL full backup files are stored.

    target_dir: indicates the directory to which data is restored. The directory has been prepared in 1. The directory must be empty. If the directory does not exist, the system automatically creates it.

    The following directories are generated after the decompression:

    • data: stores full backup data. The recovery.done file has been deleted.
    • xlog: stores incremental backup data.
    • tblspc: stores tablespace directory files (if the original backup contains tablespace files).

  7. Copy the files in 6 to the specified directory of the local database.

    1. Copy all the decompressed files in the data directory to the data directory of the local database, and then replace the three files in the data directory of the local database with the configuration files saved in step 3.
    2. Copy the decompressed files in the xlog directory to the pg_xlog or pg_wal folder in the data directory of the local database. (The folder names vary according to database versions.)
    3. Move the decompressed tablespace folder (if any) in the tblspc directory to the tablespace directory created in step 1 and modify the soft link of the corresponding tablespace in data\tablespace_map.

  8. Reboot the database and wait until the database restoration is complete.

FAQs

Data Restoration

Q: How do I restore data if no backup is available?

A: For details, see Restoring a DB Instance.

Backup and Restoration Operations

Q: After I restored data to a self-built database using an RDS backup, the database failed to start and the error message "replication slot file xxx has corrupted length xxx" was displayed. What should I do?

A: Manually delete all files and folders from the pg_replslot directory and then start the database.

Q: Why does the recovery.done file not exist in the backup?

A: For PostgreSQL 12 and later versions, recovery.done has been deleted.

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel