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.
- Get log space size
- View wait statistics data
- Clear wait statistics data
- Clear latch statistics data
Let’s discuss each of above tasks as use cases of DBCC SQLPERF command.
Read More
- How to get total no of VLFs (Virtual Log Files) inside Log file?
- Understanding Data Files, Pages & Extents
- How to Avoid Page Split in SQL Server?
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.
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.
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.
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.
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.
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.
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.
Related Articles
- Should We Clear Wait Stats Data from DMV sys.dm_os_wait_stats?
- How to Fix BACKUPBUFFER Wait Type?
- How to Improve Bulk Data Load Performance?
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.
- How to Fix SQL Error 1005: A Comprehensive Guide - April 9, 2023
- How to Fix SQL Server Error 207 – Invalid Column Name - April 9, 2023
- How to Fix SQL Error 1045: Resolving Access Denied Issues - April 8, 2023
