search
HomeComputer TutorialsComputer KnowledgeMethods and steps for compressing database log files

Methods and steps for compressing database log files

How to compress database log files

There are three specific methods.

method one:

first step:

backup log database_name with no_log

or backup log database_name with truncate_only

-- no_log and truncate_only are synonymous here, you can execute any sentence.

Step 2:

1. Shrink all data and log files of a specific database, execute:

dbcc shrinkdatabase (database_name,[,target_percent])

-- database_name is the name of the database to be shrunk; target_percent is the percentage of remaining free space required in the database file after the database is shrunk.

2. Shrink the data or log files in a specific database at a time, execute

dbcc shrinkfile(file_id,[,target_size])

-- file_id is the identification (ID) number of the file to be shrunk. To obtain the file ID, use the FILE_ID function or search sysfiles in the current database; target_size is the desired file size in megabytes (using expressed as an integer). If not specified, dbcc shrinkfile reduces the file size to the default file size. Both dbcc can have the parameter notruncate or truncateonly. For details, see the online help.

Method Two:

first step:

Back up the entire database first to prepare for emergencies.

Step 2:

After the backup is completed, execute the following statement in Query Analyzer:

exec sp_detach_db yourDBName,true

--Uninstall the registration information of this DB in MSSQL

third step:

Go to the directory where the physical log file is located to delete the log file or move the log file out of the directory

the fourth step:

Execute the following statement in Query Analyzer:

exec sp_attach_single_file_db yourDBName,'

d:\mssql\data\yourDBName_data.mdf '

--Register the DB as a single file. If successful, MSSQL will automatically generate a 500K log file for this DB.

Method 3:

1. Enter the Enterprise Manager and select the database, such as demo

2. All tasks->Separate database

3. Go to the directory where the database file is stored and delete the MuOnline_log.LDF file. Just in case, you can copy it out

4. Enterprise Manager -> Attach database, select muonline. At this time, you will see that the log file item is a cross. It does not matter, continue. At this time, the database will prompt you whether to create a new one if the database has no logs. That’s it for sure.

5. Remember that the user needs to reset it after the database is reattached.

If you don’t want it to get bigger in the future:

Used under SQL2000:

Right-click on the database->Properties->Options->Failure Recovery-Model-Select-Simple Model.

Or use SQL statement:

alter database database name set recovery simple

What to do if the SQL database is too large

--1. Daily database compression

--Compress log and database file size

/*--pay attention

Please follow the steps. If you have not completed the previous steps, please do not do the following steps

Otherwise it may damage your database.

--*/

1. Clear the log

DUMP TRANSACTION library name WITH NO_LOG

2. Truncate transaction log:

BACKUP LOG database name WITH NO_LOG

3. Shrink the database file (if not compressed, the database file will not be reduced

Enterprise Manager--right-click the database you want to compress--All tasks--Shrink database--Shrink files

--Select the log file--In the shrink mode, select shrink to XXM. A minimum number of M allowed to be shrunk will be given here. Enter this number directly and confirm.

--Select the data file--In the shrink mode, select shrink to XXM. There will be a minimum number of M allowed to be shrunk. Enter this number directly and confirm.

You can also use SQL statements to complete

--Shrink database

DBCC SHRINKDATABASE(Customer Data)

--Shrink the specified data file, 1 is the file number, which can be queried through this statement: select * from sysfiles

DBCC SHRINKFILE(1)

4. In order to minimize the log file size (if it is SQL 7.0, this step can only be performed in the query analyzer)

a. Separate database:

Enterprise Manager--Server--Database--Right-click--Detach Database

b. Delete LOG files on my computer

c. Additional database:

Enterprise Manager--Server--Database--Right-click--Attach Database

This method will generate a new LOG, the size is only more than 500K

or use code:

The following example detaches pubs and then appends a file in pubs to the current server.

a.Separation

EXEC sp_detach_db @dbname = 'pubs'

b. Delete log files

c.Add

EXEC sp_attach_single_file_db @dbname = 'pubs',

@physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'

5. In order to automatically shrink in the future, make the following settings:

Enterprise Manager--Server--right-click the database--Properties--Options--Select "Auto Shrink"

--SQL statement setting method:

EXEC sp_dboption 'database name', 'autoshrink', 'TRUE'

6. If you want to prevent the log from growing too large in the future

Enterprise Manager--Server--Right-click Database--Properties--Transaction Log

--Limit file growth to xM (x is the maximum data file size you allow)

--SQL statement setting method:

alter database database name modify file(name=logical file name, maxsize=20)

The above is the detailed content of Methods and steps for compressing database log files. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
Is Outriders Crossplay Not Working? Why and How to Fix It? - MiniToolIs Outriders Crossplay Not Working? Why and How to Fix It? - MiniToolMay 10, 2025 am 12:03 AM

What is Outriders Crossplay? How to enable it? Is Outriders Crossplay not working? If you are hit by this annoying issue, how to get rid of the trouble? Take it easy and go to see this post from php.cn to know much information about the game.

How to Use ChatGPT on Android and iOS Devices? See the Guide! - MiniToolHow to Use ChatGPT on Android and iOS Devices? See the Guide! - MiniToolMay 10, 2025 am 12:02 AM

Is ChatGPT available on Android & iOS? How to use ChatGPT on mobile devices? If you wonder about questions to these queries, this post could help you. Here, php.cn offers a detailed guide to you to help you easily run ChatGPT on your iPhone and A

Get ms-resource:AppName/Text Issue in Windows 11/10? Fix It!Get ms-resource:AppName/Text Issue in Windows 11/10? Fix It!May 10, 2025 am 12:01 AM

What is ms-resource:AppName/Text in Windows 11/10? How to remove this prominent problem from your PC? Take it easy if you suffer from this issue, go to find out what you should do to address it in this post on the php.cn website.

Notion Download, Install, Update, and Reset on Windows/Mac - MiniToolNotion Download, Install, Update, and Reset on Windows/Mac - MiniToolMay 09, 2025 am 12:54 AM

The Notion is a popular productivity program used for note-taking and organizing your thoughts, projects, and information. If you have not tried it yet, you should give it a chance. This article about Notion download on php.cn Website will give you a

How to Fix SSL Certificate Error in FireFox/Chrome? - MiniToolHow to Fix SSL Certificate Error in FireFox/Chrome? - MiniToolMay 09, 2025 am 12:53 AM

SSL certificate error is a common error when using a browser. Why does it occur and how to fix it on Windows 10/11? Follow the suggestions in this post on php.cn Website, you can resolve it easily.

Fix Windows Defender Exclusions Not Working Windows 11/10 - MiniToolFix Windows Defender Exclusions Not Working Windows 11/10 - MiniToolMay 09, 2025 am 12:52 AM

Do you know what is the Windows Defender exclusions? Do you have any idea how to exclude a folder from Windows Defender Windows 11/10? What if Windows Defender exclusions not working? Read this post given by php.cn to get the answers.

Windows 10 22H2 First Preview Build: Windows 10 Build 19045.1865 - MiniToolWindows 10 22H2 First Preview Build: Windows 10 Build 19045.1865 - MiniToolMay 09, 2025 am 12:51 AM

Microsoft has just released Windows 10 build 19045.1865 to the Release Preview Channel. This is the first preview build for Windows 10 22H2. php.cn Software will show you some related information about this build in this post.

Steam Not Downloading at Full Speed? A Quick Guide Here!Steam Not Downloading at Full Speed? A Quick Guide Here!May 09, 2025 am 12:50 AM

Steam gains large popularity among game players all around the world for its rich variety of games. However, have you ever encountered Steam not downloading at full speed? Why is Steam not downloading at full speed? If your Steam download speed drops

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!