Help: SQL Server

Sharing my knowlege about SQL Server Troubleshooting Skills

Posts Tagged ‘ssms’

SSMS Internals : What is the meaning of Wait Category in Activity Monitor Under Resource Waits

Posted by blakhani on November 27, 2014


Recently I was working with a friend on performance issue and she asked an simple question.

I use activity monitor tool which is provided with management studio. When I look at the Resource Waits group, there is a column called Wait Category. What does that show and how data is picked? Here is the screenshot from my machine.

At almost same time, same question popped in Facebook group (SQLBangalore) as well. So I decided to dig into more details. Captured the profiler and found that Activity Monitor uses two DMVs to show the values in that section (Resource Waits).

  • sys.dm_os_wait_stats is used to get information for completed waits
  • sys.dm_os_waiting_tasks for threads that are in an in-progress wait.

Here are the various waits we could potentially see.

Wait Category Count(Type)
Backup 7
Buffer I/O 12
Buffer Latch 6
Compilation 3
Full Text Search 3
Idle 26
Latch 9
Lock 21
Logging 5
Memory 6
Network I/O 6
Other 120
Parallelism 3
SQLCLR 17
Transaction 18
User Waits 1

 

How did I find this? By running profiler! As per profiler, the waits related information in Activity Monitor (AM) is populated by procedure #am_generate_waitstats. This is created when AM is launched. The temporary table which is populated in #am_wait_types which has mapping of “display” values and DMV values.

 

category_name wait_type ignore
Backup BACKUP 0
Backup BACKUP_CLIENTLOCK 0
Backup BACKUP_OPERATOR 0
Backup BACKUPBUFFER 0
Backup BACKUPIO 0
Backup BACKUPTHREAD 0
Backup DISKIO_SUSPEND 0
Buffer I/O ASYNC_DISKPOOL_LOCK 0
Buffer I/O ASYNC_IO_COMPLETION 0
Buffer I/O FCB_REPLICA_READ 0
Buffer I/O FCB_REPLICA_WRITE 0
Buffer I/O IO_COMPLETION 0
Buffer I/O PAGEIOLATCH_DT 0
Buffer I/O PAGEIOLATCH_EX 0
Buffer I/O PAGEIOLATCH_KP 0
Buffer I/O PAGEIOLATCH_NL 0
Buffer I/O PAGEIOLATCH_SH 0
Buffer I/O PAGEIOLATCH_UP 0
Buffer I/O REPLICA_WRITES 0
Buffer Latch PAGELATCH_DT 0
Buffer Latch PAGELATCH_EX 0
Buffer Latch PAGELATCH_KP 0
Buffer Latch PAGELATCH_NL 0
Buffer Latch PAGELATCH_SH 0
Buffer Latch PAGELATCH_UP 0
Compilation RESOURCE_SEMAPHORE_MUTEX 0
Compilation RESOURCE_SEMAPHORE_QUERY_COMPILE 0
Compilation RESOURCE_SEMAPHORE_SMALL_QUERY 0
Full Text Search SOAP_READ 0
Full Text Search SOAP_WRITE 0
Full Text Search MSSEARCH 0
Idle ONDEMAND_TASK_QUEUE 1
Idle REQUEST_FOR_DEADLOCK_SEARCH 1
Idle RESOURCE_QUEUE 1
Idle LOGMGR_QUEUE 1
Idle KSOURCE_WAKEUP 1
Idle LAZYWRITER_SLEEP 1
Idle BROKER_RECEIVE_WAITFOR 1
Idle CHECKPOINT_QUEUE 1
Idle CHKPT 1
Idle BROKER_EVENTHANDLER 1
Idle BROKER_TRANSMITTER 1
Idle SERVER_IDLE_CHECK 1
Idle SNI_HTTP_ACCEPT 1
Idle SLEEP_BPOOL_FLUSH 1
Idle SLEEP_DBSTARTUP 1
Idle SLEEP_DCOMSTARTUP 1
Idle SLEEP_MSDBSTARTUP 1
Idle SLEEP_SYSTEMTASK 1
Idle SLEEP_TASK 1
Idle SLEEP_TEMPDBSTARTUP 1
Idle SQLTRACE_BUFFER_FLUSH 1
Idle TRACEWRITE 1
Idle WAITFOR_TASKSHUTDOWN 1
Idle WAIT_FOR_RESULTS 1
Idle XE_DISPATCHER_WAIT 1
Idle XE_TIMER_EVENT 1
Latch VIEW_DEFINITION_MUTEX 0
Latch DEADLOCK_ENUM_MUTEX 0
Latch LATCH_DT 0
Latch LATCH_EX 0
Latch LATCH_KP 0
Latch LATCH_NL 0
Latch LATCH_SH 0
Latch LATCH_UP 0
Latch INDEX_USAGE_STATS_MUTEX 0
Lock LCK_M_BU 0
Lock LCK_M_IS 0
Lock LCK_M_IU 0
Lock LCK_M_IX 0
Lock LCK_M_RIn_NL 0
Lock LCK_M_RIn_S 0
Lock LCK_M_RIn_U 0
Lock LCK_M_RIn_X 0
Lock LCK_M_RS_S 0
Lock LCK_M_RS_U 0
Lock LCK_M_RX_S 0
Lock LCK_M_RX_U 0
Lock LCK_M_RX_X 0
Lock LCK_M_S 0
Lock LCK_M_SCH_M 0
Lock LCK_M_SCH_S 0
Lock LCK_M_SIU 0
Lock LCK_M_SIX 0
Lock LCK_M_U 0
Lock LCK_M_UIX 0
Lock LCK_M_X 0
Logging LOGBUFFER 0
Logging LOGMGR 0
Logging LOGMGR_FLUSH 0
Logging LOGMGR_RESERVE_APPEND 0
Logging WRITELOG 0
Memory UTIL_PAGE_ALLOC 0
Memory SOS_RESERVEDMEMBLOCKLIST 0
Memory SOS_VIRTUALMEMORY_LOW 0
Memory LOWFAIL_MEMMGR_QUEUE 0
Memory RESOURCE_SEMAPHORE 0
Memory CMEMTHREAD 0
Network I/O ASYNC_NETWORK_IO 0
Network I/O DBMIRROR_SEND 0
Network I/O NET_WAITFOR_PACKET 0
Network I/O OLEDB 0
Network I/O MSQL_DQ 0
Network I/O DTC_STATE 0
Other EXECUTION_PIPE_EVENT_INTERNAL 0
Other FAILPOINT 0
Other INTERNAL_TESTING 0
Other IO_AUDIT_MUTEX 0
Other KTM_ENLISTMENT 0
Other KTM_RECOVERY_MANAGER 0
Other KTM_RECOVERY_RESOLUTION 0
Other MSQL_SYNC_PIPE 0
Other MIRROR_SEND_MESSAGE 0
Other MISCELLANEOUS 0
Other MSQL_XP 0
Other REQUEST_DISPENSER_PAUSE 0
Other PARALLEL_BACKUP_QUEUE 0
Other PRINT_ROLLBACK_PROGRESS 0
Other QNMANAGER_ACQUIRE 0
Other QPJOB_KILL 0
Other QPJOB_WAITFOR_ABORT 0
Other QRY_MEM_GRANT_INFO_MUTEX 0
Other QUERY_ERRHDL_SERVICE_DONE 0
Other QUERY_EXECUTION_INDEX_SORT_EVENT_OPEN 0
Other QUERY_NOTIFICATION_MGR_MUTEX 0
Other QUERY_NOTIFICATION_SUBSCRIPTION_MUTEX 0
Other QUERY_NOTIFICATION_TABLE_MGR_MUTEX 0
Other QUERY_NOTIFICATION_UNITTEST_MUTEX 0
Other QUERY_OPTIMIZER_PRINT_MUTEX 0
Other QUERY_REMOTE_BRICKS_DONE 0
Other QUERY_TRACEOUT 0
Other RECOVER_CHANGEDB 0
Other REPL_CACHE_ACCESS 0
Other REPL_SCHEMA_ACCESS 0
Other DBMIRROR_WORKER_QUEUE 0
Other DBMIRRORING_CMD 0
Other DBTABLE 0
Other DAC_INIT 0
Other DBCC_COLUMN_TRANSLATION_CACHE 0
Other DBMIRROR_DBM_EVENT 0
Other DBMIRROR_DBM_MUTEX 0
Other DBMIRROR_EVENTS_QUEUE 0
Other DEADLOCK_TASK_SEARCH 0
Other DEBUG 0
Other DISABLE_VERSIONING 0
Other DLL_LOADING_MUTEX 0
Other DROPTEMP 0
Other DUMP_LOG_COORDINATOR 0
Other DUMP_LOG_COORDINATOR_QUEUE 0
Other DUMPTRIGGER 0
Other EC 0
Other EE_PMOLOCK 0
Other EE_SPECPROC_MAP_INIT 0
Other ENABLE_VERSIONING 0
Other ERROR_REPORTING_MANAGER 0
Other FSAGENT 1
Other FT_RESTART_CRAWL 0
Other FT_RESUME_CRAWL 0
Other FULLTEXT GATHERER 0
Other GUARDIAN 0
Other HTTP_ENDPOINT_COLLCREATE 0
Other HTTP_ENUMERATION 0
Other HTTP_START 0
Other IMP_IMPORT_MUTEX 0
Other IMPPROV_IOWAIT 0
Other ABR 0
Other BROKER_REGISTERALLENDPOINTS 0
Other BROKER_SHUTDOWN 0
Other BROKER_TASK_STOP 1
Other BAD_PAGE_PROCESS 0
Other BROKER_CONNECTION_RECEIVE_TASK 0
Other BROKER_ENDPOINT_STATE_MUTEX 0
Other CURSOR 0
Other CURSOR_ASYNC 0
Other BUILTIN_HASHKEY_MUTEX 0
Other CHECK_PRINT_RECORD 0
Other BROKER_INIT 0
Other BROKER_MASTERSTART 0
Other SOSHOST_EVENT 0
Other SOSHOST_INTERNAL 0
Other SOSHOST_MUTEX 0
Other SOSHOST_RWLOCK 0
Other SOSHOST_SEMAPHORE 0
Other SOSHOST_SLEEP 0
Other SOSHOST_TRACELOCK 0
Other SOSHOST_WAITFORDONE 0
Other SOS_STACKSTORE_INIT_MUTEX 0
Other SOS_SYNC_TASK_ENQUEUE_EVENT 0
Other SHUTDOWN 0
Other SOS_CALLBACK_REMOVAL 0
Other SOS_DISPATCHER_MUTEX 0
Other SOS_LOCALALLOCATORLIST 0
Other SOS_OBJECT_STORE_DESTROY_MUTEX 0
Other SOS_PROCESS_AFFINITY_MUTEX 0
Other SNI_CRITICAL_SECTION 0
Other SNI_HTTP_WAITFOR_0_DISCON 0
Other SNI_LISTENER_ACCESS 0
Other SNI_TASK_COMPLETION 0
Other SEC_DROP_TEMP_KEY 0
Other SEQUENTIAL_GUID 0
Other VIA_ACCEPT 0
Other SQLSORT_NORMMUTEX 0
Other SQLSORT_SORTMUTEX 0
Other WAITSTAT_MUTEX 0
Other WCC 0
Other WORKTBL_DROP 0
Other XE_BUFFERMGR_ALLPROCECESSED_EVENT 0
Other XE_BUFFERMGR_FREEBUF_EVENT 0
Other XE_DISPATCHER_JOIN 0
Other SQLTRACE_LOCK 0
Other SQLTRACE_SHUTDOWN 0
Other SQLTRACE_WAIT_ENTRIES 0
Other SRVPROC_SHUTDOWN 0
Other TEMPOBJ 0
Other THREADPOOL 1
Other TIMEPRIV_TIMEPERIOD 0
Other XE_TIMER_MUTEX 0
Other XE_TIMER_TASK_DONE 0
Other XE_MODULEMGR_SYNC 0
Other XE_OLS_LOCK 0
Other XE_SERVICES_MUTEX 0
Other XE_SESSION_CREATE_SYNC 0
Other XE_SESSION_SYNC 0
Other XE_STM_CREATE 0
Parallelism CXPACKET 1
Parallelism EXCHANGE 1
Parallelism EXECSYNC 1
SQLCLR CLR_AUTO_EVENT 1
SQLCLR CLR_CRST 0
SQLCLR CLR_JOIN 0
SQLCLR CLR_MANUAL_EVENT 1
SQLCLR CLR_MEMORY_SPY 0
SQLCLR CLR_MONITOR 0
SQLCLR CLR_RWLOCK_READER 0
SQLCLR CLR_RWLOCK_WRITER 0
SQLCLR CLR_SEMAPHORE 0
SQLCLR CLR_TASK_START 0
SQLCLR CLRHOST_STATE_ACCESS 0
SQLCLR ASSEMBLY_LOAD 0
SQLCLR FS_GARBAGE_COLLECTOR_SHUTDOWN 0
SQLCLR SQLCLR_APPDOMAIN 0
SQLCLR SQLCLR_ASSEMBLY 0
SQLCLR SQLCLR_DEADLOCK_DETECTION 0
SQLCLR SQLCLR_QUANTUM_PUNISHMENT 0
Transaction TRAN_MARKLATCH_DT 0
Transaction TRAN_MARKLATCH_EX 0
Transaction TRAN_MARKLATCH_KP 0
Transaction TRAN_MARKLATCH_NL 0
Transaction TRAN_MARKLATCH_SH 0
Transaction TRAN_MARKLATCH_UP 0
Transaction TRANSACTION_MUTEX 0
Transaction XACT_OWN_TRANSACTION 0
Transaction XACT_RECLAIM_SESSION 0
Transaction XACTLOCKINFO 0
Transaction XACTWORKSPACE_MUTEX 0
Transaction DTC_TMDOWN_REQUEST 0
Transaction DTC_WAITFOR_OUTCOME 0
Transaction MSQL_XACT_MGR_MUTEX 0
Transaction MSQL_XACT_MUTEX 0
Transaction DTC 0
Transaction DTC_ABORT_REQUEST 0
Transaction DTC_RESOLVE 0
User Waits WAITFOR 1

 

Hope this helps in understanding Activity monitor wait category little better.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Advertisements

    Posted in Internals, SQL Server Management Studio, SSMS | Tagged: , , , , , , , | 3 Comments »

    Tips and Tricks: One Query – Multiple Servers – One Result Set

    Posted by blakhani on September 9, 2014


    How many times you have been into a situation where you need to run one query across many servers? I have asked his question from one of the DBA and his answer was I will create a linked server and then modify the query to refer linked server. Well this needs modification to server configuration and most of the production server don’t allow changed without change request.

    The better approach would be to use an under-estimated feature of SQL Server Management Studio called as Multiserver query. This can be done via by creating a group and registering one or more registered servers within the groups. Once group is created then we can query the complete group and the result format can be customized. Pinal (b|t) has written a blog here. This is a extension of that blog in little more details. 

    To get to below option we need to open “Registered Servers” Window. If you don’t see it hit Ctrl+Alt+G or go to View > Registered Servers. I have registered two server under a group called “Fake Production”. We can created your own hierarchy to logically group the servers. Display Name can also be changed in this windows. I have given a name as “HiddenName” to one of my instance for display purpose. Effectively I have 4 Servers under “Local Server Groups” and 2 Servers under “Fake Production Group”

    We can right click on any of the node and choose “New Query” as shown below.

    First thing you would notice is that the color of status bar is changed. Also notice that we can see how many servers are connected out of total servers. For demo purpose I have used different account to connect each server that’s why we are seeing “<various logins>”

    Color Customization can be done by going to Tools > Option > Text Editor > Editor Tab and Status Bar as shown below.

     

    From above, we can also change other setting for status bar but they are not specified to multi-server.

    If we ran a query in this query window, it would run on all the servers and give results.

    We are seeing same number of databases on 1st and 4th row in my lab because they are same servers. dot (.) and (local) both means local server.

    This result can be customized using “Tools > Option > Query Results > SQL Server > Multiserver Results” as below

    Note: We can’t join two tables across the servers using multiserver query feature.

    Hope this would help in getting some quick reports from various servers.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in Tips and Tricks | Tagged: , , | Leave a Comment »

    Troubleshooting : Error – Incorrect syntax near ‘GO’

    Posted by blakhani on August 28, 2014


    Sometimes we are very comfortable and used to with certain things that if they change, we become nervous and uneasy. I have a lovely daughter and she always greets me when I come back home from office. That one “hello” takes away all my worries and I feel alive. Yesterday she didn’t do that and I was worried. I checked with my wife and she told that there was a mild fever and her mood is little different today. That made me little nervous.

    Same feeling happened when I saw below in management studio of my colleague:

    Msg 102, Level 15, State 1, Line 2

    Incorrect syntax near ‘GO’.

    image

     

    and management studio intellisense feature was also complaining about syntax. “Incorrect syntax near ‘End Of File’. Expecting ‘=’. As per documentation “GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor”

    I went to Tools > Option in Management studio and found that there was a customization done on batch separator. SSMS> Tools > Options >Query Execution > SQL Server > General > Batch Separator.

    Which means if I run with “come” it should work and as expected.

    image

    Perfect! This mystery is solved now. This made me think that can we customize SQLCMD as well. If we look into help of SQLCMD we can see parameter -c cmdend

    image

    Here is the usage of parameter –c . I have used hello as command end parameter and hello works same as go in true sense.

    image

    I hope this clears some confusion about batch separator.

    If you are getting this error while using ExecuteNonQuery in .net program and running script then refer http://blogs.msdn.com/b/onoj/archive/2008/02/26/incorrect-syntax-near-go-sqlcommand-executenonquery.aspx which has a workaround.

    Hope this helps!

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in SSMS, Troubleshooting | Tagged: , , , , , , | 2 Comments »