• Relational Database Service

  1. Help Center
  2. Relational Database Service
  3. User Guide
  4. Working with RDS for PostgreSQL
  5. Migrating PostgreSQL Data Using psql
  6. Exporting Data

Exporting Data

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

  • 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 device that can access RDS prepared in 1 in section Preparing for Data Migration.
  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 password for the RDS DB instance as prompted.


    [rds@localhost ~]$ pg_dump --username=root --host= --port=5432 --format=plain --file=backup.sql my_db

    Enter the password of user root as prompted.

    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