sqlserver log file

Process: The database crashed yesterday afternoon, and the performance was that it could not connect to the database. After restarting the service, it was fine.

 

              查询日文文件 , “Autogrow of file 'XX_log' in database 'XX' was cancelled by user or timed out after 1896 milliseconds. Use ALTER DATABASE to set a smaller FILEGROWTH value for this file or to explicitly set a new file size.”。

              Found the reason: The database is growing automatically, so the connection timed out.

Analysis: The database log file is full and starts to grow automatically. The automatic growth method is 10% by default. There is no problem in the early stage, but in the later stage. The log file is huge, only tens of gigabytes, and ten percent of the tens of gigabytes has several gigabytes. Therefore, if you allocate such a large space on the disk, it is easy to time out.

 

Solution: Set the automatic growth mode to fixed. If it is too small, it will easily cause disk fragmentation. If it is too large, it will easily time out. Generally 500M is no problem.

                   Operation: Right-click the database, properties, files, auto-growth.

 

Others: The files of the sqlserver database include mdf files and ldf files. mdf is the data file and ldf is the log file. If there is a complete log file, the database can be restored to the state at any point in time. The importance of log files can be seen, but log files generally grow rapidly, so they need to be shrunk regularly.

             

USE [ master ]   
GO   
ALTER  DATABASE database name SET RECOVERY SIMPLE WITH NO_WAIT  
 GO   
ALTER  DATABASE database name SET RECOVERY SIMPLE    --simple mode   GO USE Rk  
 GO DBCC SHRINKFILE (N ' database name_log ' , 2 , TRUNCATEONLY)   -- after setting compression The log size is 2M, you can specify   GO USE [ master ] GO ALTER DATABASE database name SET RECOVERY FULL
  
  

  
  
  
  WITH NO_WAIT  
 GO   
ALTER  DATABASE database name SET RECOVERY FULL   -- restore to full mode   
GO  

      It can be divided into three steps, set the data table to simple mode, shrink it, and then set it back to full mode.

 

    The database has three modes, simple recovery mode, complete recovery mode, and large-capacity log recovery mode, you can see here https://www.cnblogs.com/OpenCoder/p/5708226.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325115873&siteId=291194637