SQL Server automatically grows too big a problem

Source: Internet
Author: User
Tags file size log backup

I. BACKGROUND

The problems we encounter are shown in the following illustration: Automatic growth is growing in such proportions;

(Figure1: Where the problem lies)

If you try to modify the automatic growth value using SSMS, the following error occurs:

(Figure2: Error message)

Faced with the above problems, we need to solve two problems:

1. The data file is shrunk to a certain range of values, freeing up disk space;

2. Reset the automatic growth of the value, you can according to the percentage, can also use the specified space size, I personally prefer to use n*1024m such values, for reference only;

3. You can also do the contraction of the log file if necessary;

Ii. the process of settlement

1. Modify the automatically growing value using the following script:

--1024
ALTER DATABASE [DataBaseName]
MODIFY FILE (NAME = N ' FileName ', filegrowth = 1024MB)
go

(Figure 3: Effect)

The above is performed in accordance with 1024MB of space execution effect, if you want to use a percentage of the following SQL:

--10%
ALTER DATABASE [DataBaseName]
MODIFY FILE (NAME = N ' FileName ', filegrowth = 10%)
go

2. Use the following script to shrink the data: (the default is in MB)

--12000MB use
[DataBaseName]
go
DBCC shrinkfile (N ' FileName ', 12000)
go

(Figure4: effect)

(Figure5: effect)

3. If there is a need you can also be a log file shrinkage: (need simple mode, if in full mode, you need to do is log file backup)

--sql server DataBaseName
BACKUP LOG [] with no_log
DBCC shrinkdatabase ([databasename],truncateonly)
    
--sql Server 2008
ALTER DATABASE [DataBaseName] SET RECOVERY simple
go
--shrink
DBCC shrinkfile (2,30)  --30 unit m, log file size go 
--Change mode to full, then change back, if it is simple, then do not need
ALTER DATABASE [DataBaseName] SET RECOVERY Full Go

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/

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.