How to clean up error logs in ms SQL Server database

Source: Internet
Author: User
Tags sql error

The SQL error log records various problems encountered during database operation and some important information. As a troubleshooting requirement, we usually do not take the initiative to clean up these log files. Only when the server is restarted, SQL automatically deletes the oldest log file and generates a new log file.
By viewing the database log files on the server, a large amount of query notification dialog information is found, and the frequency of occurrence is very high, resulting in a very fast increase of log files.

Google understands the relationship between this error and the message mechanism of the service broker. You can use the trace tag DBCC TraceOn (4133,-1) to eliminate this information.
However, the most urgent task is to clear the log information. The simplest way is to delete these log files in the SQL log directory. However, before deletion, you must stop the SQL Server service, this may cause data loss in the cache. Therefore, this is not recommended.
So what should we do?
Execute the following statement:
EXEC sp_cycle_errorlog;
Each time the SQL statement is executed, a log file is automatically initialized to clear the log Content. If the SQL statement contains 7 log files (default), perform this operation seven times, each time, the oldest log file is cleared.
Readers don't have to worry that clearing will take a long time. I have a log of 40 Gb here. After the command is executed, the file is cleared immediately. This method is especially convenient when the time is urgent.
Is there a way to set a fixed size for each log file?
I have checked this information. Someone said that the size of ErrorLogSizeInKb can be set in the registry, but it is limited to SQL2012. Other versions of the database do not take effect. I have not verified this, if you are interested, you can discuss it together.
Database error-free recovery
Cause: the customer's SqlServer version is 2000. Due to the large log size, no space is available, and the customer wants to delete the log after separating the database (it is said that the GB log =. =). Then, an error is displayed, but the database is detached after refreshing. After deleting the log, the database cannot be appended. After online query, the following methods are summarized, fortunately, useful tables are not damaged. Only the statistical table data is damaged, but it does not matter. The job will reset these tables.
-- Make sure that the enterprise manager does not open any database
-- Set the database emergency status
Use master
Go
Sp_configure 'Allow updates', 1
Go
Reconfigure with override
Go
-- Set the database to emergency mode
Update sysdatabases set status =-32768 where dbid = DB_ID ('provision ')
-- Rebuild the Database Log File
Dbcc rebuild_log ('procurement ', 'd: \ Procurement_log.ldf ')
-- Verify Database Consistency (omitted)
Dbcc checkdb ('signature ')
-- Set the database to normal
Sp_dboption 'procurement ', 'dbo use only', 'false'
-- In the last step, we need to restore the "allow direct modification to the system directory" set in Step E.
Sp_configure 'Allow updates', 0
Go
Reconfigure with override
Go
Now your database allows connection. Now you can check whether there is a problem with the data in each table. If there is a problem, you can only find professional data to reply.

Related Article

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.