• Home
  • About Us
  • Contact Us
  • Privacy Policy
  • Special Offers
Business Intelligence Info
  • Business Intelligence
    • BI News and Info
    • Big Data
    • Mobile and Cloud
    • Self-Service BI
  • CRM
    • CRM News and Info
    • InfusionSoft
    • Microsoft Dynamics CRM
    • NetSuite
    • OnContact
    • Salesforce
    • Workbooks
  • Data Mining
    • Pentaho
    • Sisense
    • Tableau
    • TIBCO Spotfire
  • Data Warehousing
    • DWH News and Info
    • IBM DB2
    • Microsoft SQL Server
    • Oracle
    • Teradata
  • Predictive Analytics
    • FICO
    • KNIME
    • Mathematica
    • Matlab
    • Minitab
    • RapidMiner
    • Revolution
    • SAP
    • SAS/SPSS
  • Humor

Simultaneous Auto-growth in Multiple Files

May 27, 2017   BI News and Info

SQL Server 2016 has a new configuration to control the auto-growth of multiple files in the same filegroup. When we create several files in the same filegroup SQL Server does a round robin across the files, writing a piece of data in each of them until all the data is finally on the files.

However, the amount of data written in each file may not be always the same. The algorithm SQL Server uses for the round robin takes into account the amount of free space in each file. Due to that, to ensure an even data distribution across the files, we need to keep the files with the same size.

If the auto-growth happens, one file will be bigger than the other, therefore the data distribution across the files will be unbalanced.

Starting in SQL Server 2016 we have a solution for this problem: The filegroups now have the “autogrow_all_files” attribute.  This attribute ensures that all files will grow together, keeping the same size.

Let’s execute a demo, step by step.

1) Create a new database. The statement below creates the database with two filegroups, the Primary and another one called FG1. You need to correct the path of the files before execute this statement.

CREATE DATABASE sales 

ON PRIMARY 

        (NAME = sales_dat, filename =
                ‘C:\MyFolder\Sales.mdf’, size = 8mb, maxsize = 500mb, filegrowth = 20% ),
filegroup fg1 — Default
        (NAME = sales_dat2, filename = ‘C:\MyFolder\Sales2.ndf’, size = 8mb, maxsize =
                 500mb, filegrowth = 20% ),

        (NAME = sales_dat3, filename =
                 ‘C:\MyFolder\Sales3.ndf’, size = 8mb, maxsize = 500mb, filegrowth = 20% )

log ON
        (NAME = sales_log, filename = ‘C:\MyFolder\Sales.ldf’, size = 20mb, maxsize =
                 unlimited, filegrowth = 10mb );
go 

2) Check the filegroups configuration. The result, in the image below, shows the default value of the attribute autogrow_all_files, disabled.

USE sales
go
SELECT NAME,is_autogrow_all_files
FROM   sys.filegroups 

AutogrowthAll05 Simultaneous Auto growth in Multiple Files

3) Let’s create a table in filegroup FG1, insert 2000 records and check the database files. The autogrowth didn’t happen yet.

CREATE TABLE test 
  (
     id    INT IDENTITY(1, 1) PRIMARY KEY,
     texto CHAR(8000)
  )
ON fg1
go
INSERT INTO test 
VALUES      (‘x’)
go 2000
EXEC Sp_helpfile
go 

AutogrowthAll02 Simultaneous Auto growth in Multiple Files

4) Using the DMV ‘sys.dm_db_database_page_allocations’ we can identify the data distribution across the files.

select extent_file_id,count(*)
 from
sys.dm_db_database_page_allocations
     (DB_ID(‘Sales’),OBJECT_ID(‘test’),1,1,‘DETAILED’)
group by extent_file_id

go

AutogrowthAll03 Simultaneous Auto growth in Multiple Files

5) Let’s insert more 20 records and check the files again. The auto-growth already happened in only one of the files.

insert into test values (‘x’)

go 20

exec sp_helpfile

AutogrowthAll04 Simultaneous Auto growth in Multiple Files

This result will unbalance the round-robin, reducing any advantage it’s creating for the environment. Let’s try the same demonstration again, this time changing the autogrow_all_files attribute of FG1 filegroup.

1) Drop and re-create the database, changing the autogrow_all_files and checking the change. Again, you need to correct the path of the files.

use master

go

drop databaseif exists Sales;

go

CREATE DATABASE Sales
 on Primary
  (NAME = Sales_dat, FILENAME = ‘C:\MyFolder\Sales.mdf’, SIZE = 8MB, MAXSIZE = 500MB, FILEGROWTH = 20% ),
 Filegroup FG1 — Default
  (NAME = Sales_dat2, FILENAME = ‘C:\MyFolder\Sales2.ndf’, SIZE = 8MB, MAXSIZE = 500MB, FILEGROWTH = 20% ),
  (NAME = Sales_dat3, FILENAME = ‘C:\MyFolder\Sales3.ndf’, SIZE = 8MB, MAXSIZE = 500MB, FILEGROWTH = 20% )
LOG ON
  (NAME = Sales_log, FILENAME = ‘C:\MyFolder\Sales.ldf’, SIZE = 20MB, MAXSIZE = UNLIMITED, FILEGROWTH = 10MB );

go

alter database Sales modify filegroup [FG1] AutoGrow_All_Files
      With Rollback Immediate

go

use sales

go

select name,is_autogrow_all_files
 from sys.filegroup

AutogrowthAll05 Simultaneous Auto growth in Multiple Files

2) Create the table, insert 2000 records and check the files.

create table test 
( id int identity(1,1) primary key,
  texto char(8000))
  on FG1

go

insert into test values (‘x’)

go 2000

exec sp_helpfile

go

AutogrowthAll06 Simultaneous Auto growth in Multiple Files

3) Insert 20 more records and check the files again. Now the auto-growth happened in both files, keeping the data distribution even across the files.

insert into test values (‘x’)

go 20 

exec sp_helpfile

AutogrowthAll07 Simultaneous Auto growth in Multiple Files

Let’s block ads! (Why?)

SQL – Simple Talk

Autogrowth, files, multiple, Simultaneous
  • Recent Posts

    • Now get Mind Map View of your Dynamics 365 CRM Connections in a single view with latest Map My Relationships features!
    • Potatoes for Brains
    • How to Prepare for Microsoft Certification Exams
    • The Missing Link: Blockchain for Digital Supply Chains
    • Incoming White House science and technology leader on AI, diversity, and society
  • Categories

  • Archives

    • January 2021
    • December 2020
    • November 2020
    • October 2020
    • September 2020
    • August 2020
    • July 2020
    • June 2020
    • May 2020
    • April 2020
    • March 2020
    • February 2020
    • January 2020
    • December 2019
    • November 2019
    • October 2019
    • September 2019
    • August 2019
    • July 2019
    • June 2019
    • May 2019
    • April 2019
    • March 2019
    • February 2019
    • January 2019
    • December 2018
    • November 2018
    • October 2018
    • September 2018
    • August 2018
    • July 2018
    • June 2018
    • May 2018
    • April 2018
    • March 2018
    • February 2018
    • January 2018
    • December 2017
    • November 2017
    • October 2017
    • September 2017
    • August 2017
    • July 2017
    • June 2017
    • May 2017
    • April 2017
    • March 2017
    • February 2017
    • January 2017
    • December 2016
    • November 2016
    • October 2016
    • September 2016
    • August 2016
    • July 2016
    • June 2016
    • May 2016
    • April 2016
    • March 2016
    • February 2016
    • January 2016
    • December 2015
    • November 2015
    • October 2015
    • September 2015
    • August 2015
    • July 2015
    • June 2015
    • May 2015
    • April 2015
    • March 2015
    • February 2015
    • January 2015
    • December 2014
    • November 2014
© 2021 Business Intelligence Info
Power BI Training | G Com Solutions Limited