About shrinking of templog log files

Unintentionally found that the templog.ldf file of the system database is very large, 500G disk space, templog.ldf occupies 101G, the first thought at the time was to shrink and rebuild the log file.

Log viewing method one: dbcc sqlperf (logspace)

Log viewing method two:

select db_name (database_id) dbname,
       type_desc , -data or log
       name -logical  name of the file 
       physical_name,
       -physical path of the  file state_desc,-file state 
       size * 8.0 / 1024 as 'file size (MB)'         
from sys.master_files 
where type_desc = 'LOG'

Because my database is the 2008 R2 version, the first thought at that time was to use the SQL 2005 processing method, truncating the transaction log and unloading and loading the database.

SQL 2005 processing

method one:

One: backup log tempdb with no log (Note: Truncating the log does not reduce the size of the physical log file, but reduces the size of the logical log file and frees up disk space for reuse)

Two: dbcc shrinkdatabase (temp, 50%) (Note: After the above execution is successful, you need to shrink the database)

Method Two:

Unload and load the database:

One: execute sp_detach_db temp (Note: uninstall the database)

Two: execute sp_attach_single_file_db temp, 'd: \ date \ templog.ldf' (Note: load the database)

In the 2008 version, the above methods are not applicable. There are many opinions on the Internet. Some replies that the system database does not allow shrinking, only the alter storage path. It was originally on the D drive, and there is no other drive in the database. I also tried to restart the server. The server does not work, if there are other drive letters, you can try this way to change the storage path

ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');

ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');

Finally, in  the post at http://bbs.csdn.net/topics/390606782 , I saw that the moderator (I do n’t want to grow up ) tried to deal with the reply. The log of 100G was reduced to 25G.

Using DBCC shrinkfile (templog, 1024), why the shrink is 1024M, templog is still 25G, strange, I remember that I used this method at the beginning, but it was unsuccessful, the details are still being studied, waiting for the gods to give pointers.

For a more detailed introduction to templog, please refer to: https://technet.microsoft.com/zh-cn/library/ms176029.aspx and http://blog.csdn.net/dba_huangzj/article/details/7641534

 

 

 

 

 

 

 

Published 22 original articles · praised 7 · 100,000+ views

Guess you like

Origin blog.csdn.net/qyx0714/article/details/60321814