patternsqlModerate
Could not obtain exclusive lock on database 'model' - who is using it?
Viewed 0 times
obtainexclusivewhocoulddatabaseusingnotmodellock
Problem
when trying to run the following query in order to create a new database:
Getting the following error message:
Msg 1807, Level 16, State 3, Line 1
Could not obtain exclusive lock on database 'model'.
Retry the operation later.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed.
Some file names listed could not be created. Check related errors.
what is using the model database and does not allow me to obtain the exclusive lock?
CREATE DATABASE [Lunch]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Lunch',
FILENAME = N'E:\Data Files\Lunch.mdf' ,
SIZE = 110592KB , FILEGROWTH = 1048576KB ),
FILEGROUP [DATA]
( NAME = N'Lunch_Data',
FILENAME = N'E:\Data Files\Lunch_Data.ndf' ,
SIZE = 110592KB , FILEGROWTH = 1048576KB ),
FILEGROUP [NONCLUSTERED_INDEXES]
( NAME = N'Lunch_nonclusteredindexes',
FILENAME = N'E:\Data Files\Lunch_nonclusteredindexes.ndf' ,
SIZE = 110592KB , FILEGROWTH = 1048576KB )
LOG ON
( NAME = N'Lunch_log',
FILENAME = N'F:\logFiles\Lunch_log.ldf' ,
SIZE = 524288KB ,
FILEGROWTH = 524288KB )
GOGetting the following error message:
Msg 1807, Level 16, State 3, Line 1
Could not obtain exclusive lock on database 'model'.
Retry the operation later.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed.
Some file names listed could not be created. Check related errors.
what is using the model database and does not allow me to obtain the exclusive lock?
Solution
Your
You can have a user that just opened an SSMS query window with the context of
Once you have found the locking session, just kill it.
model database is locked now so what you should do is to find out the session that has a lock on it, this can be done using sys.dm_tran_locks:select request_session_id
from sys.dm_tran_locks
where resource_type = 'database' and
resource_database_id = 3 and
request_type = 'LOCK' and
request_status = 'GRANT';You can have a user that just opened an SSMS query window with the context of
model database and did not ever execute any query there, but that session still holds S lock on the database resource.Once you have found the locking session, just kill it.
Code Snippets
select request_session_id
from sys.dm_tran_locks
where resource_type = 'database' and
resource_database_id = 3 and
request_type = 'LOCK' and
request_status = 'GRANT';Context
StackExchange Database Administrators Q#216773, answer score: 13
Revisions (0)
No revisions yet.