Microsoft SQL Server
ALTER DATABASE baza SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Above command does:
- Forces all of the users from database.
- Restricts access to database to all users:
- except one and only user that has executed the command
- any other user even super-user can not get access to database
- even the same user that put database in single user mode but in second connection is restricted to database
Db2
QUIESCE DATABASE IMMEDIATE
- Forces all users from database.
- Restricts access to database to all users:
- except all users with SYSADM, SYSMAINT, DBADM, or SYSCTRL authorities.
Is there single user mode in Db2 v11.5/Linux, so only one single user that has put database into single user mode has access to it in one single session?
1 Answer 1
In our case all users are connecting to database using TCP/IP protocol. I somehow made a work-around by temporally disable TCPIP protocol.
Connect to Linux server with SSH.
Disabled TCPIP.
db2set DB2COMM=
Stop instance.
db2stop force
Do the task I want to do in "single user" mode.
Set back TCPIP and start instance.
db2set DB2COMM=TCPIP db2start
I know this is not true "single use" mode. Disadvantages:
- if there are multiple databases in instance, all databases will lose TCP/IP connections
- if there are local Db2 tasks within Linux itself, they will not be blocked
- it is required to coordinate between administrators, so some other admin does not start the database
connect to <dbname> in exclusive mode
?SELECT 1 FROM TABLE (MON_GET_CONNECTION (NULL, -2)) WHERE APPLICATION_HANDLE <> MON_GET_APPLICATION_HANDLE() LIMIT 1
returns a row.