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
- Using the SQL client tool to connect to the database.
- 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.
- 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;
- Run the following command to delete the database again:
1
DROP DATABASE [ IF EXISTS ] database_name;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot