• Relational Database Service

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

Importing Data

This section describes how to use an ECS or a device that can access RDS to connect to a DB instance and import the exported SQL file into RDS.

Procedure

  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 into 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

    Enter the password of user root as prompted.

  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)