Friday, January 28, 2011

GhostCleanupTask & Exception Error 1222

If you experience Exception Error 1222 Severity 16 State 18 with the SPID being less than 50 and the LoginName shows 'sa', then these may be generated by the GhostCleanupTask.

To verify if indeed the GhostCleanupTask is the cause, try add the EventClasses 'Exception', 'Lock:Timout' and 'SQLTransaction' as well as filter on the LoginName 'sa' in SQL Server Profiler.

As mentioned in this link http://support.microsoft.com/kb/920093 the below will stop these errors:

DBCC TRACEON (661,-1)

To re-enable the GhostCleanupTask use:

DBCC TRACEOFF (661,-1)

Thursday, January 13, 2011

Extended Events Quick Test Code

Below is an example of creating, starting, viewing, stopping and dropping an extended event in SQL Server 2008.

-- Code to create an extended event
CREATE EVENT SESSION sqlkevin
ON SERVER
-- obtain events using SELECT * FROM sys.dm_xe_objects WHERE object_type = 'event' ORDER BY name
-- sqlserver below is used by comparing package_guid in sys.dm_xe_objects with name in SELECT * FROM sys.dm_xe_packages
ADD EVENT sqlserver.checkpoint_begin
-- obtain target for results by using SELECT * FROM sys.dm_xe_objects WHERE object_type = 'target'
-- package0 below is used by comparing package_guid in sys.dm_xe_objects with name in sys.dm_xe_packages
ADD TARGET package0.asynchronous_file_target
-- obtain SET permissions for this target from SELECT * FROM sys.dm_xe_object_columns WHERE object_name = asynchronous_file_target'
-- re below, look in the description column in sys.dm_xe_object_columns for more info
(SET filename = N'C:\sqlkevin_testlog.xel', metadatafile = N'C:\sqlkevin_testmetadata.xem')

-- Code to start an extended event
ALTER EVENT SESSION sqlkevin
ON SERVER
STATE = START

-- Code to see extended event
SELECT * FROM sys.server_event_sessions
SELECT * FROM sys.server_event_session_actions
SELECT * FROM sys.server_event_session_events
SELECT * FROM sys.server_event_session_fields
SELECT * FROM sys.server_event_session_targets
SELECT * FROM sys.dm_xe_sessions
SELECT * FROM sys.dm_xe_session_targets
SELECT * FROM sys.dm_xe_session_events
SELECT * FROM sys.dm_xe_session_object_columns

-- Create an Event
CHECKPOINT

-- Read the output file
-- Note that if there is no data to check point you may have to retry the below select statement until a checkpoint occurs
SELECT * FROM sys.fn_xe_file_target_read_file
('C:\sqlkevin_testlog*.xel', 'C:\sqlkevin_testmetadata*.xem', null, null)

-- Code to stop an extended event
ALTER EVENT SESSION sqlkevin
ON SERVER
STATE = STOP

-- Code to remove an extended event
DROP EVENT SESSION sqlkevin
ON SERVER
 

SQL Server and disk drives with 512 emulation (512e)

Interesting article about the 512e mode on hard disks when used with SQL Server.

Key extract from this link

'For SQL Server the best recommendation is to work with the hardware manufacture to make sure the 512e mode is disabled on drives that hold the SQL Server database and log files and that the Windows API is reporting 4K sector sizes.'

Further reading:

DBMIRROR_DBM_EVENT Wait Type Observation

In SQL Server 2008, if you change the mirrored databases from synchronous to asynchronous mode, the DBMIRROR_DBM_EVENT wait type does not appear to occur on the principal server.