When trying to drop a database in PostgreSQL, it failed with the following error message:
11:32:15 AMStarted executing query at Line 1
database "sampledb" is being accessed by other users
Total execution time: 00:00:05.016
Whoops, seems that our database is still in use. Letās kill all active connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
pg_terminate_backend (pg_stat_activity.pid) | |
FROM | |
pg_stat_activity | |
WHERE | |
pg_stat_activity.datname = 'sampledb'; |
Letās now try to execute the drop database again:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP DATABASE sampledb; |