The solution of the MSSQL database is full

Source: Internet
Author: User

The current workaround is to remove the other files on the hard disk to empty the hard disk space, change the database log file size to unrestricted, and then separate the database, to ensure that the separation is successful, and then delete the database log file (preferably renamed first, just in case). Then attach the database, which rebuilds the log file.

Add back, the database to automatic contraction, the log file to increase by MB, the maximum growth is set to a fixed value, the size of the value of data processing, there is Osashi update operation, should be set to a larger point.

working on Query Analyzer
Empty log
DUMP TRANSACTION Library name with NO_LOG
Truncate the transaction log:
BACKUP LOG database name with NO_LOG

Troubleshooting SQL database Log full
1. Right-click database → properties → options → fault restore model → set to simple → OK;
2. Right-click database → All tasks → shrinking database → OK;
3. Right-click database → properties → options → fault restore model → set to bulk logging → OK.

Ii. Complex methods
1. Empty the Log
DUMP TRANSACTION Library name with NO_LOG
2. Truncate the transaction log
BACKUP LOG database name with NO_LOG
3. Shrink the database file (if not compressed, the database file does not decrease)
Enterprise Manager--right-click the database you want to compress--all tasks--shrink the database--Shrink the file
--Select the log file--in the contraction mode to choose to shrink to XXM, here will give a allowed to shrink to the minimum number of M, directly enter this number, OK.
--Select the data file--choose Shrink to XXM in the contraction mode, here will give a allowable shrinkage to the minimum m number, directly enter this number, OK.
You can also use SQL statements to complete
--Shrinking database
DBCC shrinkdatabase (Customer profile)
--Shrinks the specified data file, 1 is the file number, which can be queried by this statement: SELECT * from Sysfiles DBCC shrinkfile (1)
4, in order to maximize the reduction of the log file (if it is SQL 7.0, this step can only be done in Query Analyzer)
A. Detaching a database
Enterprise Manager--server--database--right--detach database
B. Delete the log file from My Computer
C. Attaching a database
Enterprise Manager--server--database--right--Attach Database
This method will generate a new log with a size of only more than 500 k
or in code:
The following example detaches pubs and then attaches a file in pubs to the current server.
A. Separation
EXEC sp_detach_db @dbname = ' pubs '
B. Deleting a log file
C. Re-attach
EXEC sp_attach_single_file_db @dbname = ' pubs ', @physname = ' C:\Program
Files\Microsoft SQL Server\mssql\data\pubs.mdf '
5, in order to be able to automatically shrink, do the following settings
Enterprise Manager--server--right-click Database-Properties--Options--select "Auto Shrink"
--sql Statement Setup Method:
EXEC sp_dboption ' database name ', ' autoshrink ', ' TRUE '
6, if you want to not let it grow too large log
Enterprise Manager--server--right-click Database--Properties--transaction log
--Limit file growth to XM (x is the largest data file size you allow)
How to set the--sql statement:
ALTER DATABASE name modify file (name= logical file name, maxsize=20)

Special attention
Please follow the steps, do not take the previous steps, please do not follow the steps, otherwise it may damage your database.
It is generally not recommended to do 4th, 62 steps, the 4th step is unsafe, it is possible to damage the database or lost data, 6th step if the log reaches the upper limit, subsequent database processing will fail and can be resumed after the log is cleaned up.
Two methods are available when the log file is full and the SQL database cannot write to the file:
One way: Empty the log.
1. Open Query Analyzer, enter a command
DUMP TRANSACTION database name with NO_LOG
2. Open Enterprise Manager again--right click on the database you want to compress--all tasks--shrink the database--Shrink the file--Select the log file--in the contraction mode to choose to shrink to XXM, here will give an allowable contraction to the minimum number of M, directly enter this number, OK.
The other approach has some risk, because SQL Server log files are not written to the database master file immediately, such as improper processing, can cause data loss.
1: Delete Log
Detach Database Enterprise Manager-> Server-> Database-> Right-click-> Detach Database
2: Delete log file
Attach Database Enterprise Manager-> Server-> Database-> Right-click-> Attach Database
This method generates a new log with a size of more than 500 K.
   Note: It is recommended to use the first method.
If later, do not want it to become larger.
Use under SQL2000:
On the database, right-click Properties--Options--model-selection-simple model.
or with an SQL statement:
ALTER DATABASE name set recovery simple
In addition, Truncate log on checkpoint (this option is used for Sql7.0,sql 2000, i.e. the recovery model is selected as a simple model) when the checkpoint command is executed if the transaction log file exceeds 70% of its size
Clear the content in the development database always set this option to true auto shrink periodically checks the database when the unused space of the database file or log file exceeds 25% of its size, the system will automatically shrink the file so that its unused space equals 25%
Files that do not shrink when the file size is not larger than the initial size when it is established must also be greater than or equal to the size of the transaction log file when the file is scaled back or truncate
Log on Checkpoint option is set to true.
   Note: Generally established database default property is set, but unexpected situation causes the database properties to be changed, after the user empties the log, check the database above properties, in case the transaction log is filled again.

The solution of the MSSQL database is full

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.