LLI Wiki — My Digital Knowledge Base

Disconnect all users and set a database to single-user

ALTER DATABASE statement that disconnects all other users at once by setting the database to SINGLE_USER with ROLLBACK IMMEDIATE.

To disconnect every other user from a database at once, set the database to single-user mode. ROLLBACK IMMEDIATE ends the other sessions and rolls back their open transactions instead of waiting for them to finish.

ALTER DATABASE <database_name>
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;

Notes

ALTER DATABASE <database_name> SET MULTI_USER;
Mastodon LLIMastodon SocialFosstodon