Thursday, November 4, 2021

What is Auto Growth ?

Auto Growth

What is Auto-growth?

· An auto-growth event is the process by which the SQL Server engine expands the size of a database file when it runs out of space. Each database has its own auto-growth setting – that is set by the default setting of the model database. Rarely do we use the model setting.

Why set up the auto-growth for each database?

· If you don’t set up the auto-growth setting for each database and be proactive in your duties, then each time an auto-growth event is performed, SQL Server holds up database processing while an auto-growth event occurs. And this can cause poor performance.

·  What is the purpose of auto-growth and it’s consequences of not setting up the auto-growth properly?

·  Each time the auto-growth event occurs, the server need to expand this space and place the space in the disk.  However, since the space allocated for the database may not be next to each other on the disk, the will cause your database file to become fragmented, thus poor performance.

· The initial settings for auto-growth are set to the default values when defining a new database. These defaults are established by using the auto-growth settings on the model database files. 

·  How can I avoid auto-growth events from occurring too many times?

·  Pre-Size your databases and size the auto-growth to an appropriate.

When an auto-growth event occurs SQL Server needs to find additional disk space in which the database can grow. Most likely this disk space will not be physically right next to the existing database space, but instead will be somewhere else on the disk. This causes your database file to be physically fragmented on the disk. The more auto-growth events you have the more physical fragmentation you will have. When your database is physically fragmented it takes longer for SQL Server to read that databases, because it has to move the disk head around to all the different fragmented pieces to read your database. To avoid the issues associated with auto-growth events you need to minimize the number of auto-growth events that occur.

SQL : 

select db_name(s.database_id), s.database_id, s.file_id, s.physical_name as file_name, s.size*8 as SizeKB, s.max_size, 

case s.is_percent_growth when 1 then convert(varchar(10), s.growth) + '%' else convert(varchar(10), s.growth*8) + 'kb' end as Growth

from sys.master_files s

where s.type = 0 --data only;


USE DATABASE_NAME GO

ALTER DATABASE <DATABASE_NAME> MODIFY FILE (NAME = 'FILENAME', SIZE = 1234, FILEGROWTH = 1234) GO

UI For Default Setting : 

RigthClick Model Database -> Properties -> Files -> Change initial size, growth size

UI For Current Database

Rightclick database -> Properties -> File -> Change initial size, growth size

 



No comments:

Post a Comment