When deleting the database, PGSQL prompts that the database has a connection session and cannot be deleted. What should I do?

Since most applications today use database connection pools, the database connection will not be disconnected immediately after the page or interface is accessed. This leads to sometimes wanting to use navicat to delete certain databases created for testing purposes. , will cause the deletion to fail and prompt

Error: database "*" is being accessed by other users Detail: There are * other sessions using the database.”,

What should you do if you encounter this situation? You can use a statement to actively terminate the connection. Just execute the following sql statement in the query window of Navicat.

SELECT CAST(pg_terminate_backend(pid) AS VARCHAR(10)) FROM pg_stat_activity WHERE datname='test-db';

Note that test-db in the above statement needs to be replaced with the name of the database you want to delete;

Guess you like

Origin blog.csdn.net/one_and_only4711/article/details/123416754