Solve the problem of shrinking Mysql transaction log and log files being too large to shrink

Solve the problem of shrinking Mysql transaction log and log files being too large to shrink

1. MS SQL SERVER 2005

--1. Clear the log
exec('DUMP TRANSACTION database name WITH NO_LOG')
--2.Truncate the transaction log:
exec('BACKUP LOG database name WITH NO_LOG')
--3. Shrink the database file (if not compressed, the database file will not be reduced
exec('DBCC SHRINKDATABASE(database name) ')
--4. Set automatic shrink
exec('EXEC sp_dboption database name,autoshrink,TRUE')

2.MS SQL SERVER 2008 & 2008r2 & 2012 & 2016

--In SQL2008, log clearing must be done in simple mode, and then switched back to full mode after the clearing operation is completed.
USE [master]
GO
ALTER DATABASE database_name SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE database name SET RECOVERY SIMPLE --Simple mode GO
USE database name GO
--crm50sp1_log is the logical name of the database log file DBCC SHRINKFILE (N'crm50sp1_log', 11, TRUNCATEONLY)
GO
USE [master]
GO
ALTER DATABASE database_name SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE database name SET RECOVERY FULL --Restore to full mode GO

3. The log file is abnormally large and cannot be shrunk

If the log file is abnormally large and cannot be shrunk, you need to check whether there are any uncommitted or rolled back transactions.

Execute the DBCC OPENTRAN command to check whether there are any transactions that have been run very early (the transaction start time is displayed in the message). If there are any transactions that have been displayed, it means that the transaction has not been committed or rolled back, so MinLSN cannot be rolled forward.
If this happens, there are two ways to do it. One is to kill the process using the process number displayed in the information. kill process number; (Of course, restarting the SQL service is also OK if downtime is allowed);

If there are no transactions that have not been closed for a long time, Simple mode: Back up the database first, then execute BACKUP LOG database name WITH NO_LOG Complete mode: If a full backup has not been performed, first perform a full backup, then back up the log file, and finally execute DBCC SHRINKFILE (N'log file logical name', 0, TRUNCATEONLY) to shrink only the log file.

The logical name of the log file can be obtained by the following statement: USE erp database go SELECT [name] FROM sys.database_files WHERE type_desc='LOG'

Summarize

The above is what I introduced to you about how to solve the problem of shrinking Mysql transaction logs and log files being too large to shrink. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to shrink the log file in MYSQL SERVER
  • How to convert mysql bin-log log files to sql files
  • Summary of basic operation commands of Binary Log binary log files in MySQL
  • Basic concepts of binary and redo log files in MySQL
  • MySQL log file details
  • Introduction to MySQL log files and log types
  • mysql binary log file restore database
  • Sharing ideas and solutions for automatically restoring MySQL database log files
  • Teach you to automatically restore the log file (binlog) of the MySQL database
  • Where is the MySQL log file? How to modify the MySQL log file location
  • Summary of important mysql log files

<<:  jQuery implements accordion small case

>>:  How to configure Nginx virtual host in CentOS 7.3

Recommend

innodb_flush_method value method (example explanation)

Several typical values ​​of innodb_flush_method f...

Determine the direction of mouse entry based on CSS

In a front-end technology group before, a group m...

Use of Linux ln command

1. Command Introduction The ln command is used to...

MySQL EXPLAIN statement usage examples

Table of contents 1. Usage 2. Output results 1.id...

Summary of how to add root permissions to users in Linux

1. Add a user . First, use the adduser command to...

js method to realize shopping cart calculation

This article example shares the specific code of ...

Vue uses Canvas to generate random sized and non-overlapping circles

Table of contents Canvas related documents Effect...

MySQL Database Basics SQL Window Function Example Analysis Tutorial

Table of contents Introduction Introduction Aggre...

Use mysql to record the http GET request data returned from the url

Business scenario requirements and implementation...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...

MySQL stored procedure in, out and inout parameter examples and summary

Stored Procedures 1. Create a stored procedure an...