Shrink the SQL Server database log LDF file)

Source: Internet
Author: User
How to shrink the SQL Server database log LDF file when the LDF file is too large
SQL Server controls the size of LDF files (clear Historical Records & set auto-shrinking)

* Clear historical records
1. In the SQL Server internal ice manager tool column-go to SQL query analyzer (SQL query analyzer)
2. Enter backup log <Your Database Name> with truncate_only
For example, backup log myxxdb with truncate_only

2. Return to SQL Server internal ice manager and right-click the database and choose [all working/compressed databases].
Click [file], select the log file in the database file, and select [compress the file to x mb (minimum value: y mb)] in [compression action].
Directly change X to its minimum value, and press [OK] to compress y.
Do not leave first. Click [file] again to check the amount of pressure, and you will find that you can press it again, but it will also change slightly! It can be pressed two or three times.

Conclusion: In fact, two commands can be completed.
Backup log datebasename with truncate_only
DBCC shrinkdatabase (datebasename)

* Set the database to automatically zoom out. The default value is off.
Method 1.
Alter database <Your Database Name> set auto_shrink on
For example, alter database myxxdb set auto_shrink on
Method 2.
Right-click the database and select the content (wait for a moment). Click the [Options] Page, select [automatic compression], and then press OK.

Two Methods for clearing SQL server logs
During usage, we often encounter very large database logs. Here we introduce two solutions ......

Method 1

In general, the contraction of the SQL database does not greatly reduce the size of the database. Its main function is to shrink the log size. This operation should be performed regularly to avoid excessive database logs.

1. Set database mode to simple mode: Open the SQL Enterprise Manager, in the root directory of the console, open Microsoft SQL Server --> SQL Server group --> double-click your server --> double-click to open the database directory --> select your database name (such as the Forum database) forum) --> then right-click and select Properties --> Select Options --> select "simple" in the fault recovery mode, and click OK to save.

2. Right-click the current database to view the shrinking database in all tasks. Generally, the default settings in the database do not need to be adjusted. Click OK directly.

3. After shrinking the database, we recommend that you set your database attributes to the standard mode. The operation method is the same as the first one, because logs are often an important basis for restoring the database in case of exceptions.

In sqlserver:

Backup log database name with no_log | truncate_only can intercept transaction logs.

However, after I perform the preceding operations in the database, the transaction log remains unchanged.

the first step is to truncate the non-active transaction logs and not contract the database. Only after the second operation is performed will the database clean up the transaction logs, delete the truncated non-active transactions and contract the transaction log files to the appropriate size.
when SQL Server is used, the log files in the Database become larger and need to be deleted. First, I separated the database, right-click the database, and choose "all tasks"> "detach the Database". After the database is detached, I can delete the log file and back up the data. After that, you can add the database to the attached database in all tasks. SQL server will prompt that the log file does not exist and ask if you want to create a new one. Just select YES, in this way, the log file is cleared. This method takes only a few minutes, but in these few minutes, you will not be able to access this database. I think this method is only applicable to small applications. For large systems, you need to find other methods.

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.