i have AzureSQL database (Provisioned - 2vCore, General Purpose) and sometimes my queries are blocked by session with SPID = -5.
I didnt find anything about this negative SPID and how to avoid blocking my queries.
Thanks for any info and help
Sessions with negative SPID are probably orphaned transactions. You cannot kill the session using KILL command as it needs a positive SPID number. Try running below query on the Azure SQL Database:
SELECT
DISTINCT(request_owner_guid) as UoW_Guid
FROM sys.dm_tran_locks
WHERE request_session_id =-5
GO
This should return a GUID like with the following format: 00000000-0000-0000-0000-000000000000
Try to kill the session using the GUID instead of the SPID as shown below:
KILL '00000000-0000-0000-0000-000000000000' -- replace GUID value with UoW_Guid value from above query
Related
I'm trying to figure out how to kill a request that took more than 3 hours to execute.
Is it possible to do so?
Thanks for your answers.
You can run sp_who to get a list of currently running sessions, or SELECT ##SPID to get the id of your current session. Once you know the SPID (Server Process ID), you can kill it with the kill command (so if you were SPID 57, you would type kill 57)
Find the process in the sys.sysprocesses table.
Contact the person associated with the process (via some combination of the hostname and loginame columns), and have them take care of it.
If that's not an option, you can get the value of the spid and kill it. For example, if the spid value is 12345, just kill 12345.
I have a large table without any indexes on it, about 27.5m rows.
I tried to delete about half of those using using BEGIN TRAN.
I then tried canceling the querie, but because it was taking long I decided to just close the Management Studio.
Now when I try to look into that table, it does not return anything, just keeps running.
When I run SELECT TOP 10 * FROM Tbl it just executes without returning anything.
But when I run SELECT TOP 10 * FROM Tbl(NOLOCK) it return 10 rows.
This tells me that it is waiting on a Rollback/Commit from my BEGIN TRAN.
I thought it would rollback automatically after closing the session and Management Studio.
How do I fix this issue?
Thanks.
Execute SP: SP_LOCK
In Results you will get SPID, DBID, OBJID, INDID, TYPE, RESOURCE,
MODE, STATUS
Now check the status column, if it is showing wait then
kill that SPID. To kill a particular SPID Execute SP: Kill 65 (Where
65 is SPID)
MSDN Forum
Apparently, this worked:
Terminate/Close connection to the database would solve this. To close connection you can try terminating sqlserver.exe from Task Manager or Activity Monitor if you have a Mac.
I 've a query that links many tables. So when executes a stored procedure it gives...
Timeout expired.
The timeout period elapsed prior to completion of the operation or the server is not responding.
What can I do for this.. May I have to increase the time out of the SQL server. I'm using SQl 2008. Could you please help me to resolve this..
When one transaction holds a lock on a data resource and another transaction requests an incompatible lock on the same resource, the request is blocked and the requester enters a wait state. By default, the blocked request keeps waiting until the blocker releases the interfering lock.
To get lock information, including both locks that are currently granted to sessions and locks that sessions are waiting for, query the dynamic management view (DMV) sys.dm_tran_locks as:
SELECT -- use * to explore other available attributes
request_session_id AS spid,
resource_type AS restype,
resource_database_id AS dbid,
DB_NAME(resource_database_id) AS dbname,
resource_description AS res,
resource_associated_entity_id AS resid,
request_mode AS mode,
request_status AS status
FROM sys.dm_tran_locks;
In the output of the query you will get the spid which is waiting for a shared/exclusive lock.You can get the involved spid's by observing rows with same res and resid values.
Further to get more information you can execute the following code to obtain connection, session, and blocking information about the processes involved in the blocking chain.
-- Connection info:
SELECT -- use * to explore
session_id AS spid,
connect_time,
last_read,
last_write,
most_recent_sql_handle
FROM sys.dm_exec_connections
WHERE session_id IN(--spid found in above query);
-- Session info
SELECT -- use * to explore
session_id AS spid,
login_time,
host_name,
program_name,
login_name,
nt_user_name,
last_request_start_time,
last_request_end_time
FROM sys.dm_exec_sessions
WHERE session_id IN(--spid found in above query);
-- Blocking
SELECT -- use * to explore
session_id AS spid,
blocking_session_id,
command,
sql_handle,
database_id,
wait_type,
wait_time,
wait_resource
FROM sys.dm_exec_requests
WHERE blocking_session_id > 0;
--SQL text of the connections involved in the blocking chain:
SELECT session_id, text
FROM sys.dm_exec_connections
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS ST
WHERE session_id IN(--spid found in above query);
Once you get involved spid's you can either KILL the spid using KILL <spid> command or set lock_timeout in your stored procedure using command: SET LOCK_TIMEOUT <milliseconds>;
Using SQL Server Management Studio
To configure the remote query timeout option
In Object Explorer, right-click a server and select Properties.
Click the Connections node.
Under Remote server connections, in the Remote query timeout box,
type or select a value from 0 through 2,147,483,647 to set the
maximum number seconds for SQL Server to wait before timing out.
See full details here
Timeouts are never in sql server, but always in the client calling them. So, if you can not tune the query (which may be the case) change the timeout in the application you use to issue the query.
So I'm trying to monitor the longest living lock in my database. The idea is that if a lock has been held for a certain amount of time, I will receive a warning in my application.
But for the life of I can't find the creation time of the locks.
I have used:
exec msdb..sp_lock
exec msdb..sp_who2
SELECT * FROM sys.dm_tran_locks
select * from sys.syslockinfo
select cmd, * from sys.sysprocesses where blocked > 0
But none of these seem to have the information I need.
Any ideas?
G
A long running transaction makes more sense which you can do by looking at database_transaction_begin_time column in sys.dm_tran_database_transactions
I've never known anyone to try and monitor locks... which is possibly why there is no start date/time information for them...
The Lock:Acquired EventClass in SQL Profiler has StartTime and EndTime. You might want to check that
There is a process that seems to be running all the time in SQL Server 2005 activity monitor. Double clicking on it produces the following query:
CREATE TABLE #tmpDBCCinputbuffer ([EVENT TYPE] NVARCHAR(512),
[PARAMETERS] INT, [EVENT Info] NVARCHAR(512))
INSERT INTO #tmpDBCCinputbuffer EXEC ('DBCC INPUTBUFFER(58)')
SELECT [EVENT Info] FROM #tmpDBCCinputbuffer
Any idea what it is? Is it dangerous?
Ironically, its the query you use to see the last query run on a connection, which is what you are doing to see what all the connections' last queries were. Including the connection you use to look at all those connections.
where's the dizzy emoticon when you need it?
http://msdn.microsoft.com/en-us/library/ms187730.aspx
Quote from SQL Server Developer Center
"DBCC INPUTBUFFER permissions default
to members of the sysadmin fixed
server role only, who can see any
SPID. Other users can see any SPID
they own. Permissions are not
transferable."
(http://msdn.microsoft.com/en-us/library/aa258826(SQL.80).aspx)
I just want to share another answer which further explains Neil N's answer.
The DBCC INPUTBUFFER(spid) command will return the text of the most recent batch executed against a specified SPID. When you double-click on a row in Activity Monitor (or right-click and select 'Details') then, under the covers, SQL Server runs the command you quoted in your post above (substituting the SPID of the selected row - 61 in your example) to return the most recent batch issued against the connection. In your example the batch actually happens to be the CREATE TABLE etc... batch that was issued by Activity Monitor to return the most recent batch!
by Chris Howarth https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6bbe405b-b7d8-4f97-9150-cf03c59d4fe3/process-wont-die?forum=sqldatabaseengine
The number 58 is what it will always return because it's its Process ID and it's the last process you run!