September 24, 2012 at 2:05 pm
I am also loving this! Thanks for contributing!
http://www.sqlservercentral.com/Forums/Topic1351590-146-1.aspx
Recently, Grant Fritchey suggested that I stick with Trace Flag 1222 only (see this link). I tried that with your code and pretty much got a blank email - no useful information. So, I went with all three trace flags, and I got much more information in the email. Unfortunately, it still did not bring down the hostname information and clientapp. Sure, we can go to the errorlog to still get it, but I don't see a good way to get that out of the errorlog and into the email. Anyone else see a good way to do it?
September 26, 2012 at 9:12 am
Love the script but wanted to be able to deploy this quicker. The final step of creating an alert I simply switched to TSQL and it achieves the same result without having to use the wizard:
--THIS GETS RUN AFTER THE JOB IS CREATED AND WILL CREATE THE ALERT
USE [msdb]
GO
declare
@jobid uniqueidentifier
set @jobid = isnull((select job_id from msdb.dbo.sysjobs where name = 'Deadlock Job'),'00000000-0000-0000-0000-000000000000')
set @jobid = LTRIM(rtrim(@jobid))
IF @jobid = '00000000-0000-0000-0000-000000000000'
BEGIN
RAISERROR('The deadlock job could not be found. Aborting!', 16, 1)
RETURN
END
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'DeadlockAlert')
BEGIN
RAISERROR('The alert already exists. Aborting!',16,1)
RETURN
END
EXEC msdb.dbo.sp_add_alert @name=N'DeadlockAlert',
@message_id=0,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=0,
@category_name=N'[Uncategorized]',
@performance_condition=N'SQLServer:Locks|Number of Deadlocks/sec|_Total|>|0',
@job_id= @jobid
GO
December 25, 2012 at 8:38 am
Nice article.
December 25, 2012 at 10:28 am
This was working like a champ for about a month and then suddenly SQL would email me and it would always say 0 rows affected. Anybody else run across this?
February 26, 2013 at 12:57 am
Hi ,
I am getting email when a deadlock happens but i am getting a blank attachment due to which i am not able to know the actual cause of the deadlock
February 26, 2013 at 1:15 am
You can write deadlock events in a table it gives you a xml
February 26, 2013 at 9:06 am
I was also getting a blank attachment for a long time. I forget exactly how I fixed it but I'm receiving the deadlock information now. I tried posting the code here but kept getting an error. If you e-mail me directly at steve.robinson@telos.com I can send you the code I'm using.
February 28, 2013 at 5:29 am
Look at the theese sample you can use theese sample to send e-mail graph of xml
only you have to write send e-mail
In here
@command= N'INSERT INTO DeadlockEvents
(AlertTime, DeadlockGraph)
VALUES (getdate(), N''$(ESCAPE_SQUOTE(WMI(TextData)))'')'
February 28, 2013 at 5:29 am
March 11, 2013 at 9:02 am
Good job Geoff..
I've received the file having the details of the deadlock(s)... which is not easy to read. Can you help undestanding me how can I manipulate this inforamtion in order to find out information like user id, session id, dbid, query/stored procedure, application through which this occurred.
March 11, 2013 at 9:30 am
Below is the output from the errorlog. I copy this to a txt file and search for loginname, spid, hostname and so forth to get the type of information you are looking for.
process id=process8dfd38 taskpriority=0 logused=364 waitresource=KEY: 13:72057594070499328 (fe0993f4251a) waittime=828 ownerId=1052394084 transactionname=user_transaction lasttranstarted=2013-02-28T21:51:51.983 XDES=0x4ca947d8 lockMode=X schedulerid=3 kpid=15148 status=suspended spid=82 sbid=0 ecid=0 priority=0 transcount=2 lastbatchstarted=2013-02-28T21:53:44.787 lastbatchcompleted=2013-02-28T21:51:51.983 hostpid=1844 loginname=BENEFITCOMPANY\vmadmin isolationlevel=read committed (2) xactid=1052394084 currentdb=13 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
In a separate message you will find the SQL, which is pretty easy to pick out.
January 3, 2014 at 12:58 am
I missed this article the first time around. Nice job, Geoff.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 3, 2014 at 8:37 am
Very nice, Geoff.
Here's a script that generates a deadlock to force the alert. Good to test the job.
Shamelessly lifted from some other forum, and since it worked for me, I am passing on the love.
--First run this code to create the tables and populate with data.
CREATE TABLE ##temp1 (Col1 INT)
CREATE TABLE ##temp2 (Col1 INT)
INSERT ##TEMP1
SELECT 1 UNION SELECT 2 UNION SELECT 3
INSERT ##TEMP2
SELECT 1 UNION SELECT 2 UNION SELECT 3
--Execute this in SSMS window #1
BEGIN TRAN
UPDATE ##temp1 SET Col1 = 4 WHERE Col1 = 3
--Delay long enough to lock ##temp1 in this process
--and allow ##temp2 to be locked in other process
WAITFOR DELAY '0:0:10'
--This is holding lock on ##temp1 waiting for ##temp2 to be released
UPDATE ##temp2 SET Col1 = 4 WHERE Col1 = 3
COMMIT TRAN
--Paste this code in another SSMS window and execute it
--SSMS window #2
BEGIN TRAN
UPDATE ##temp2 SET Col1 = 4 WHERE Col1 = 3
--Delay long enough to lock ##temp2 in this process
--and allow ##temp1 to be locked in other process
WAITFOR DELAY '0:0:10'
--This is holding lock on ##temp2 waiting for ##temp1 to be released
UPDATE ##temp1 SET Col1 = 4 WHERE Col1 = 3
COMMIT TRAN
/*
SELECT * FROM ##temp1
SELECT * FROM ##temp2
SELECT @@trancount
DROP TABLE ##temp1
DROP TABLE ##temp2
*/
Cheers
January 3, 2014 at 1:35 pm
Hi, thanks, I will try this
January 8, 2014 at 9:20 am
Well written article. Have you looked at using Event Notifications since I believe the default trace was deprecated since the release of SQL 2012? Event Notifications can capture the Deadlock graph.
Jonathan Kehayias has a great article on Event Notifications, Extended Events, and even the default trace. http://www.sqlskills.com/blogs/jonathan/event-notifications-vs-extended-events/
Viewing 15 posts - 46 through 60 (of 69 total)
You must be logged in to reply to this topic. Login to reply