El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Migrating Data to RDS for PostgreSQL Using psql

Updated on 2022-12-22 GMT+08:00

Preparing for Data Migration

PostgreSQL supports logical backups. You can use the pg_dump logical backup function to export backup files and then import them to RDS using psql.

You can access RDS DB instances through an EIP or through an ECS.

Preparations

  1. Prepare an ECS for accessing DB instances in the same VPC or prepare a device for accessing RDS through an EIP.
    • To connect to a DB instance through an ECS, you must first create an ECS.
    • To connect to a DB instance through an EIP, you must:
      1. Bind an EIP to a DB instance. For details, see Binding an EIP.
      2. Ensure that the local device can access the EIP that has been bound to the DB instance.
  2. Install the PostgreSQL client on the prepared ECS or device.
    NOTE:

    The PostgreSQL client version must be the same as the version of RDS for PostgreSQL. The PostgreSQL database or client will provide pg_dump and psql.

Exporting Data

Before migrating an existing PostgreSQL database to RDS, you need to export the PostgreSQL database.

NOTICE:
  • The export tool must match the DB engine version.
  • Database migration is performed offline. Before the migration, you must stop any applications using the source database.
  1. Log in to the ECS or the device that can access RDS.
  2. Use the pg_dump tool to export the source database into an SQL file.

    pg_dump --username=<DB_USER> --host=<DB_ADDRESS> --port=<DB_PORT> --format=plain --file=<BACKUP_FILE> <DB_NAME>

    • DB_USER indicates the database username.
    • DB_ADDRESS indicates the database address.
    • DB_PORT indicates the database port.
    • BACKUP_FILE indicates the name of the file to which the data will be exported.
    • DB_NAME indicates the name of the database to be migrated.

    Enter the database password as prompted.

    Example:

    $ pg_dump --username=root --host=192.168.151.18 --port=5432 --format=plain --file=backup.sql my_db

    Password for user root:

    After this command is executed, a backup.sql file will be generated as follows:

    [rds@localhost ~]$ ll backup.sql

    -rw-r-----. 1 rds rds 2714 Sep 21 08:23 backup.sql

Importing Data

You can connect your client to RDS and import exported SQL files into RDS.

  1. Ensure that the destination database to which data is to be imported exists.

    If the destination database does not exist, run the following command to create a database:

    # psql --host=<RDS_ADDRESS> --port=<DB_PORT> --username=root --dbname=postgres -c "create database <DB_NAME>;"
    • RDS_ADDRESS indicates the IP address of the RDS DB instance.
    • DB_PORT indicates the RDS DB instance port.
    • DB_NAME indicates the name of the database to be imported.

  2. Import the exported file to RDS.

    # psql --host=<RDS_ADDRESS> --port=<DB_PORT> --username=root --dbname=<DB_NAME> --file=<BACKUP_DIR>/backup.sql

    • RDS_ADDRESS indicates the IP address of the RDS DB instance.
    • DB_PORT indicates the RDS DB instance port.
    • DB_NAME indicates the name of the database to which data is to be imported. Ensure that the database exists.
    • BACKUP_DIR indicates the directory where the backup.sql file is stored.

    Enter the password for the RDS DB instance as prompted.

    Example:

    # psql --host=172.16.66.198 --port=5432 --username=root --dbname=my_db --file=backup.sql

    Password for user root:

  3. View the import result.

    my_db=> \l my_db

    In this example, the database named my_db has been imported.

    my_db=> \l my_db
    List of databases
    Name  | Owner | Encoding | Collate     | Ctype       | Access privileges
    ------+-------+----------+-------------+-------------+-----------
    my_db | root  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
    (1 row)

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback