Home Computer Tutorials Computer Knowledge Methods and steps for compressing database log files

Methods and steps for compressing database log files

Jan 15, 2024 pm 12:51 PM
c database compression

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I edit the Registry? (Warning: Use with caution!) How do I edit the Registry? (Warning: Use with caution!) Mar 21, 2025 pm 07:46 PM

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

Discover How to Fix Drive Health Warning in Windows Settings Discover How to Fix Drive Health Warning in Windows Settings Mar 19, 2025 am 11:10 AM

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

How do I manage services in Windows? How do I manage services in Windows? Mar 21, 2025 pm 07:52 PM

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

which application uses ene.sys which application uses ene.sys Mar 12, 2025 pm 01:25 PM

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

How do I use the Group Policy Editor (gpedit.msc)? How do I use the Group Policy Editor (gpedit.msc)? Mar 21, 2025 pm 07:48 PM

The article explains how to use the Group Policy Editor (gpedit.msc) in Windows for managing system settings, highlighting common configurations and troubleshooting methods. It notes that gpedit.msc is unavailable in Windows Home editions, suggesting

How do I change the default app for a file type? How do I change the default app for a file type? Mar 21, 2025 pm 07:48 PM

Article discusses changing default apps for file types on Windows, including reverting and bulk changes. Main issue: no built-in bulk change option.

MSConfig Keeps Reverting to Selective Startup? 2 Solutions Here MSConfig Keeps Reverting to Selective Startup? 2 Solutions Here Mar 28, 2025 pm 12:06 PM

Are you questioned about an issue that MSConfig keeps reverting to selective startup on your Windows? How to switch to normal startup if you require it? Try the methods explained in this php.cn post to find one that works for you.

Windows Metadata and Internet Services Problem: How to Fix It? Windows Metadata and Internet Services Problem: How to Fix It? Apr 02, 2025 pm 03:57 PM

You may see the “A connection to the Windows Metadata and Internet Services (WMIS) could not be established.” error on Event Viewer. This post from php.cn introduces how to remove the Windows Metadata and Internet Services problem.

See all articles