File shrinkage and removal

Source: Internet
Author: User

Shrink the data file (to make room, no way can only shrink files) during the process of encountering log backup, error

 Use [dba_monitor] GO DBCC Shrinkfile (N'dba_monitor'276000)GO
View Code


Wait for log backup to finish, shrink data file again, error

The query learns that the initial size of the file can be modified

-- Modify the initial size of the file, the current size of the base plus 1M  Use [master] GO ALTER DATABASE [dba_monitor] FILE = N'dba_monitor'=  283649024KB)GO
View Code

The contraction is normal again.
A database is found to have two log files, and SQL Server writes the log records in strict order. So although there are two log files here, SQL Server writes only one of them at a point in time. SQL Server will write to the other one only if the file is full. So joining multiple log files is not going to help much in performance.
How do I confirm which log file is currently in use?
You can use the DBCC LOGINFO command to view the Fileid of the current status>0

Create Table#loginfo (FileIdint, FileSizeint, Startoffsetbigint, fseqnobigint, Statusint, Parityint, CREATELSNvarchar( +))Insert  into#loginfoexec('DBCC LOGINFO')Select *  from#loginfowhereStatus>0Drop Table#loginfo
View Code

How to delete redundant log files
First, empty the extra log file, and then delete the empty log file

--Step1 emptying files by migrating data to other files in the same filegroup Use [Dba_monitor]GODBCCShrinkfile (N'dba_monitor_log2', Emptyfile)GO--Step2 Remove the emptied log file Use [Dba_monitor]GOALTER DATABASE [Dba_monitor]REMOVEFILE [dba_monitor_log2]GO
View Code

File shrinkage and removal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.