• Relational Database Service

rds
  1. Help Center
  2. Relational Database Service
  3. User Guide
  4. Working with RDS for PostgreSQL
  5. Managing Tablespaces

Managing Tablespaces

Scenarios

RDS provides the PostgresQL tablespace management solution based on user root.

Creating a Tablespace

  1. Connect to the database as user root and create a tablespace.

    # psql --host=<RDS_ADDRESS> --port=<DB_PORT> --dbname=<DB_NAME> --username=root -c "select control_tablespace ('create', '<TABLESPACE_NAME>');"

    • RDS_ADDRESS indicates the IP address of the RDS DB instance.
    • DB_PORT indicates the RDS DB instance port.
    • DB_NAME indicates the database name.
    • TABLESPACE_NAME indicates the tablespace name.

    Enter the password of user root as prompted.

    Log in to the my_db database and create the tbspc1 tablespace. Example:

    # psql --host=192.168.6.141 --port=5432 --dbname=my_db --username=root -c "select control_tablespace('create', 'tbspc1');"

    Password for user root:
              control_tablespace          
    ------------------------------    
    create tablespace tbspc1 successfully.   
    (1 row)

    If the creation fails, view error logs of the DB instance.

    NOTE:

    To ensure performance, a maximum of 20 tablespaces can be created.

Deleting a Tablespace

Connect to the database as user root and delete a tablespace.

# psql --host=<RDS_ADDRESS> --port=<DB_PORT> --username=root --dbname=<DB_NAME> -c "select control_tablespace('drop', '<TABLESPACE _NAME>');"

  • RDS_ADDRESS indicates the IP address of the RDS DB instance.
  • DB_PORT indicates the RDS DB instance port.
  • DB_NAME indicates the database name.
  • TABLESPACE_NAME indicates the tablespace name.

Enter the password of user root as prompted.

Example:

# psql --host=192.168.6.141 --port=5432 --dbname=my_db --username=root -c "select control_tablespace('drop', 'tbspc1');"

Password for user root:
         control_tablespace         
----------------------------    
drop tablespace tbspc1 successfully.   
(1 row)

Before deleting the tablespace, ensure that it is empty. If the deletion fails, view error logs of the DB instance.