4 Different Usages of DBCC SQLPERF in SQL Server

DBCC SQLPERF is very useful command that we use to get multiple statistics related information in SQL Server. This command provides transaction log space statistics and wait statistics information at instance level and we also use it to reset wait and latch statistics data. We can use DBCC SQLPERF command to do below tasks.

  1. Get log space size
  2. View wait statistics data
  3. Clear wait statistics data
  4. Clear latch statistics data

Let’s discuss each of above tasks as use cases of DBCC SQLPERF command.

Read More

Get Transaction Log space using DBCC SQLPERF

We can get transaction log space utilization details like how large your transaction logs are and what percentage of them is in use by executing dbcc sqlperf command. Run below command to get the log space details of all database hosted your SQL Server Instance.

--Get Transaction Log Size Details
DBCC SQLPERF(logspace)

You can see the below screenshot; all the columns are self-explanatory. We can see percent of log space used out of total space allocated to the log file.

Check Log space utilization using dbcc sqlperf

View and Clear Wait Statistics Data

We can get wait statistics data using dbcc sqlperf command as well. We used to get these details using dbcc sqlperf command in older version of SQL Server instances. Although, you can still get wait statistics data using this command in current versions of SQL Server but now there is a better way to get such details using DMV sys.dm_os_wait_stats.  Here, I will show you wait stats data using DMV only. Run below commands to get wait statistics details of your SQL Server instance.

--Get wait Statistics using DBCC command.
DBCC SQLPERF(waitstats)

--Get Wait Statistics using DMV sys.dm_os_wait_stats
SELECT * FROM sys.dm_os_wait_stats
Order by wait_time_ms desc

You can see the details about all wait types on your SQL Server instance. You can also see the total wait time in milliseconds. These information is very important to deal with performance issues but details like total wait time, total waiting tasks count are not the real-time values. These values are accumulated since last SQL Server service start or last time wait stats was reset using dbcc sqlperf command. It is highly recommended to not clear wait stats data until it is required to do that otherwise you will lose valuable information about wait statistics. Read attached article about why should you not clear wait statistics data stored in DMV sys.dm_os_wait_stats.

View Wait stats data using DMV

If you want to get the correct waiting task counts or waiting time then you need to clear the wait statistics data using dbcc sqlperf command. Here, I will show you the difference after clearing the wait stats. Run below command to clear all wait stats data on your SQL Server Instance.

DBCC SQLPERF(“sys.dm_os_wait_stats”, CLEAR)

You can see I have successfully ran this command in below screenshot.

clear wait stats

Now we will again run same command to get the wait statistics data. I ran it and I get below data that is showing different than the one showing before clearing wait stats. This way you can better analyze your database performance and waiting tasks and time to reach on any conclusion.

Check wait stats after clearing its buffer

 

Clear Latch Statistics Data

I described about clearing wait stats data in above section. Here, I will show you how to clear latch statistics data. Latches are locks for RAM memory structures to prevent concurrent access and ensure serial execution of kernel code. You can run SQL command to check current latch statistics data.

--Get latch statistics data
SELECT * FROM sys.dm_os_latch_stats
ORDER BY wait_time_ms desc

You can see current latch statistics details that is also not showing only real time value but it is accumulated data since last SQL Server service restarted or last time latch wait statistics was reset/cleared.

Get Latch Statistics Data

 

Now we will clear these latch statistics data to get real time value of latch details. Run below dbcc sqlperf command to clear the latch statistics.

DBCC SQLPERF(“sys.dm_os_latch_stats”, CLEAR)

You can see we have successfully executed above command on our SQL Server Instance.

Clear Latch Statistics Data

Now go ahead and run same SQL command to get the latch statistics again. You can see now there is no waiting requests on our SQL Server Instance and you are getting real time value about latches.

latch details after cleaning its buffer data

Related Articles

These are the 4 use cases of DBCC SQLPERF command that we use during different database activities. I hope you like this article. Please follow our Facebook page and Twitter handle to get latest updates.

Manvendra Deo Singh
Follow me:

Manvendra Deo Singh

I am working as a Technical Architect in one of the top IT consulting firm. I have expertise on all versions of SQL Server since SQL Server 2000. I have lead multiple SQL Server projects like consolidation, upgrades, migrations, HA & DR. I love to share my knowledge. You can contact me on my social accounts for any consulting work.
Manvendra Deo Singh
Follow me:
Summary
4 Different Usages of DBCC SQLPERF in SQL Server
Article Name
4 Different Usages of DBCC SQLPERF in SQL Server
Description
DBCC SQLPERF is very useful command that we use to get multiple statistics related information in SQL Server. This command provides transaction log space usage statistics and wait statistics information at instance level and we also use it to reset wait and latch statistics.
Author
Publisher Name
www.techyaz.com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *