百度智能云

All Product Document

          Relational Database Service

          Cloud Migration on PostgreSQL

          Introduction

          RDS PostgreSQL supports the user to complete the migration of the self-built database in the offline mode. To ensure the data synchronization, recommend the user to execute shutdown action upon the offline migration.

          Overview

          When the data source for migration is based on the PostgreSQL database, the RDS (Relational Database Service) is fully compatible with the PostgreSQL database. So, migrating the original database to the RDS instance is similar to that from one PostgreSQL server to another PostgreSQL server. This process can be realized via the "pg_dump" tool.

          Migration Process

          Create a BCC Instance

          After the users create an RDS instance, the system provides the users with the RDS instance's domain name and port, e.g., postgresql94.example.rds.bj.baidubce.com:3306. For details, see RDS Operations Guide Create RDS Instance.

          Create database and account

          After creating an RDS instance on the console, the users continue creating the required database and account therein, and allocate the corresponding read/write privilege. For details, see RDS Operations Guide Create Database and RDS Operations Guide Create Account.

          Export of user data

          1. Export user data using "pg_dump"

          Take advantage of the "pg_dump" tool to export the data files, which will be imported into RDS instance, from the users' PostgreSQL data source (this step only involves data export, and excludes storage process, trigger, and function). The command format is as follows:

          ${pgdir}/bin/pg_dump –h ${ip} -p ${port} –d ${db_name} –U
          ${user} -f ${datadir}/${db_name}.sql

          Description of parameters:

          Parameters Description
          ${pgdir} Path for the users' local installation of PostgreSQL
          ${ip} IP address for the users' local PostgreSQL service
          ${port} Port for the users' local PostgreSQL service
          ${user} User name for the users' local PostgreSQL database
          ${db_name} Name of the users' local self-built database for migration
          ${datadir} Path of the file generated from the users' local backup
          ${db_name}.sql Name of the file generated from the users' local backup

          Migration of data to RDS through the BCC

          1. Upload the backup files to the BCC. For cloud server usage, see Operations Guide Manage Cloud Server. Here, we take Linux server as an example, provided that the path of the uploaded file on the cloud server is:

            /tmp/${db_name}.sql

          2. Migrate the data to RDS
            Export the uploaded data files into purchased RDS instance using cloud server, and the command format is:

            ${pgdir}/bin/psql –U ${rds_user} –h ${rds_ip} –p
            ${port} -d ${rds_db_name} -f /tmp/${db_name}.sql

          Description of parameter:

          Parameters Description
          ${rds_ip} For RDS instance's domain name, see Operations Guide Usage of RDS Instance
          ${rds_user} For RDS database account, see Operations Guide Manage Database Account
          ${rds_db_name} For database name in RDS, see Operations Guide Manage Database
          ${port} Port for PostgreSQL service in RDS
          ${db_name}.sql Name of the file generated from the users' local backup

          Notices:

          Since the account has the privilege of access to every database, you need to create the database for data import in RDS beforehand and grant the user account read/write privilege. Only by doing so can you successfully import the data.

          When the data migration is completed, you may take advantage of the database client tool or program to connect to the database via RDS instance connection address, port number, database account, and password.

          Previous
          Best Practices for the MySQL Slow Log
          Next
          Cloud Migration on SQL-Server