-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathPMDB.Remove database locks.sql
57 lines (44 loc) · 1.82 KB
/
PMDB.Remove database locks.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*--------------------------------------------------------------------------+
| Purpose: Remove database locks on the server
| Note: SQLCmdMode Script
+---------------------------------------------------------------------------*/
:setvar _server "Server1"
:setvar _user "***username***"
:setvar _password "***password***"
:setvar _database "PMDB_TEST"
:connect $(_server) -U $(_user) -P $(_password)
USE [$(_database)];
GO
PRINT '====================================================================='
PRINT 'show the blocked processes. '
PRINT '====================================================================='
GO
SELECT
[Database Name] = DB_NAME([dbid])
, *
FROM [master].[dbo].[sysprocesses] WITH(NOLOCK)
WHERE [BLOCKED] != 0;
--DB_NAME(dbid) = 'PMDB_TEST' -- change the database name here
PRINT '====================================================================='
PRINT 'show the blocked process record. '
PRINT '====================================================================='
GO
SELECT
[Database Name] = DB_NAME([dbid])
, *
FROM [master].[dbo].[sysprocesses];
WHERE SPID = 212 -- update the spid here
PRINT '====================================================================='
PRINT 'get the sql statement of the blocked process for the ticket. '
PRINT '====================================================================='
GO
DBCC INPUTBUFFER(212); -- update the spid here
PRINT '====================================================================='
PRINT 'remove the blocked process. '
PRINT '====================================================================='
GO
--KILL 212;
PRINT '====================================================================='
PRINT 'Finished!'
PRINT '====================================================================='
GO