All Products
Search
Document Center

ApsaraDB RDS:The "There are 2 other sessions using the database" error message appears when you delete an ApsaraDB RDS for PostgreSQL database

Last Updated:Aug 24, 2023

Issue

The following error message appears when you delete an ApsaraDB RDS for PostgreSQL database:

ERROR: database "mctest" is being accessed by other users Details: There are 2 other sessions using the database.

Cause

The database is used in other connections.

Solution

Note

Take note of the following items:

  • Before you perform high-risk operations, for example, modify the configurations or data of Alibaba Cloud instances, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
  • You can modify the configurations and data of Alibaba Cloud instances, such as Elastic Compute Service (ECS) and ApsaraDB RDS instances. We recommend that you create snapshots or enable RDS log backup before you modify instance configurations or data.
  • If you granted permissions to users or submitted sensitive information such as logon usernames and passwords in Alibaba Cloud Management Console, we recommend that you modify the information at the earliest opportunity.

  1. Run the following command to terminate all connections to the mctest database:
    select pg_terminate_backend(pid) from (select pid from pg_stat_activity where datname = '[$Database_Name]' ) a;
    Note

    Note :[$Database_Name] is the name of the database that you want to delete.

  2. Delete the database.

Applicable scope

  • ApsaraDB RDS for PostgreSQL