Performance OptimizationAndTroubleshootingHundred-day discussion(3)-monitoring using DBCC commandsLogsSpace usage
In fact, when talking about logs, there will be a lot of topics. Can you say that reasonable planning and in-depth research on logs play a crucial role in performance, it can even be said that "Success logs, failure logs ". Some friends may have said this too much, but this is the case, but we do not pay too much attention to it at ordinary times, because logs are too common, but it is a common thing, what should we do with it?Internal MechanismHow much knowledge has been learned about log-related storage, management, and performance problems.
Note: You can check the recorded"Log troubleshooting and performance optimization video.
Today, we will focus on how to monitor log usage.
We know that everyDatabaseThere is a corresponding log file (of course, we can split the log file into several log files, but this does not help the performance, it only plays a role in management and space usage ). Each log records DML activities, and log files can also be used for data recovery.
For logs, there are two serious files:
1. Log growth exceeds the expected speed. For example, we thought the log growth was 100 mb per day, but it actually increased by 200 MB per day.
2. An error occurred while the log file is full (9002)
Of course, in the case of emergency, you can temporarily reduce the amount of money, but in some cases, even if you drop the money, the problem cannot be solved because the problem is not found.
Let's talk about how to use the DBCC command to diagnose some problems. Of course, there are many methods. Not all of them are listed in this article. Never be partial to full.
In SQL Server, we use a lot of DBCC commands for database management.DBCC sqlperfThis command can be used to monitor the log file size.
In the following example, we will obtain the log space usage of all databases. BesidesDBCC sqlperfIn addition to monitoring log usage, you can also use this command to reset wait and valve lock information.
If DBCC sqlperf accepts logspace, the log usage is returned. If you want to reset the wait information, you can input several other parameters.
Use the DBCC sqlperf command to return several useful data columns: Database Name, log size (MB), and log space used (% ).
Next we will go to practice.
First, open the SQL Server Management Interface.
Then, enter the following command: DBCC sqlperf (logspace)
The result is as follows:
In fact, this may not solve the problem, but we can also view more things, as shown below:
Because this article focuses on how to use commands and functions, we will not talk about it for the time being. We will continue to learn more about it.