SQL2008 How to empty the compressed database log

Source: Internet
Author: User

SQL2008How to empty the compressed database log

Written by: Zho Chuwen

2015-4-10

recently in the initialization of a system data, continuous import and export, so accidentally, will be the data SQL ( sql2008r2 ) is that the log file is larger than the database, which brings trouble to the system deployment. So find out if you can quickly reduce the log file to a satisfactory 504K.

here today, I want to share with you SQL2008 how to clear the log document, here to do a summary, for reference. Interested students, you can explore and study together, or skip it.

1. adopted me before in SQL2005 the method found in does not work correctly:

--sql 2005

1 DUMPTRANSACTIONEcm withNo_log
2BACKUPLOGEcm withNo_log
3DBCCShrinkdatabase (ECM)

2.           because sql2008 is optimized for file and log management, so the following statements are in sql2005 can run but in sql2008 has been canceled:

Method One:

in the SQL2008 The purge log must be done in simple mode, and then back to full mode when the purge action is complete.

1--SQL
2
3 Use[Master]
4GO
5ALTERDATABASEEcmSETRECOVERY Simple withNo_wait
6GO
7ALTERDATABASEEcmSETRECOVERY Simple--Simple Mode
8GO
9 UseEcm
TenGO
OneDBCCShrinkfile (N'Scs_log', One, truncateonly)

-- note here that to use the database logical name

1 GO

2 Use[Master]
3 GO
4
5ALTERDATABASEEcmSETRECOVERY Full withNo_wait
6
7GO
8
9ALTERDATABASEEcmSETRECOVERY Full--revert to Full mode
TenGO

Advantage: This purge log runs short of elapsed time, 90GB The log can be cleared in minutes or so, and a full backup will be done within minutes .

can be completed.

Disadvantages: However, this action is best not to be used frequently, as it will result in system fragmentation. log and DIFF backups can be truncated in normal state.

appropriate environment used by this statement: When the system's log file grows abnormally or is backed up LOG the time is too long to be used in cases where production is affected.

Method Two:

one of the simplest methods is:
detaching a database
Cut (note is cut, not deleted)*.ldfto another directory
Attach the database, select*.mdffile, creating a new log file when attached
after confirming that there are no problems, delete the log files.

If you encounter an inability to detach, please stop the service before doing it.

3 , for more technology sharing, you can join our technology group.

Welcome to join the technology sharing group: 238916811



SQL2008 How to empty the compressed database log

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.