Help Center> GaussDB(DWS)> Troubleshooting> Database Use> Failed to Delete a Database and an Error Is Reported Indicating that a Session Is Connected to the Database
Updated on 2024-01-25 GMT+08:00

Failed to Delete a Database and an Error Is Reported Indicating that a Session Is Connected to the Database

Symptom

A database cannot be deleted and an error is reported indicating that a session is connected to the database.

Possible Causes

A session is still connected to the database, or a session keeps connecting to the database. Therefore, the database fails to be deleted. Check the database to find out whether there is a connected session. If such a session exists, find the machine that connects to the database, disconnect the connection, and delete the database.

Handling Procedure

  1. Using the SQL client tool to connect to the database.
  2. Run the following command to view the current sessions:

    1
    SELECT * FROM pg_stat_activity;
    

    Key fields in the query result are described as follows:

    • datname: name of the database to which the user session connects
    • usename: name of the user who connects to the database
    • client_addr: IP address of the client host that connects to the database

    In the query result, find the name of the database to be deleted and the IP address of the corresponding client host.

  3. Check the host and applications that connect to the database based on the IP address of the client host, and stop the connections.

    1
    CLEAN CONNECTION TO ALL FOR DATABASE xxx;
    

  4. Run the following command to delete the database again:

    1
    DROP DATABASE [ IF EXISTS ] database_name;