Skip to Content

I had a session
about trace flags this year on the SQL Day 2014 conference that was held in
Wrocław at the end of April. The session topic is important to most of DBA’s
and the reason I did it was that I sometimes forget about various trace flags
:). So I decided to prepare a presentation but I think it is a good idea to
write posts about trace flags, too.

Let’s start then
– today I will describe the TF 1117. I assume that we all know how to setup a
TF using starting parameters or registry or in the session or on the query
level. I will always write if a trace flag is local or global to make sure we
know how to use it.

Why do we need
this trace flag? Let’s create a test database first. This is quite ordinary
database as it has two data files (4 MB each) and a log file that has 1MB. The
data files are able to expand by 1 MB and the log file grows by 10%:

USE [master]




( NAME = N’TF1117′,

     FILENAME = N’C:\Program Files\Microsoft SQL

     SIZE = 4096KB ,


= 1024KB


( NAME = N’TF1117_1′,

     FILENAME = N’C:\Program Files\Microsoft SQL

     SIZE = 4096KB ,


= 1024KB



( NAME = N’TF1117_log’,

     FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\DATA\TF1117_log.ldf’

     SIZE = 1024KB ,

     MAXSIZE = 2048GB ,

= 10%



Without the TF
1117 turned on the data files don’t grow all up at once. When a first file is
full the SQL Server expands it but the other file is not expanded until is
full. Why is that so important? The SQL Server proportional fill algorithm will
direct new extent allocations to the file with the most available space so new
extents will be written to the file that was just expanded. When the TF 1117 is
enabled it will cause all files to auto grow by their specified increment. That
means all files will have the same percent of free space so we still have the
benefit of evenly distributed IO. The TF 1117 is global flag so it affects all
databases on the instance. Of course if a filegroup contains only one file the
TF does not have any effect on it.

Now let’s do a
simple test. First let’s create a table in which every row will fit to a single
page: The table definition is pretty simple as it has two integer columns and
one character column of fixed size 8000 bytes:

create table TF1117Tab


     col1 int,

     col2 int,

     col3 char (8000)



Now I load some
data to the table to make sure that one of the data file must grow:

declare @i int

select @i = 1

while (@i < 800)


      insert into TF1117Tab  values (@i, @i+1000, ‘hello’)

       select @i= @i + 1


I can check the
actual file size in the sys.database_files DMV:

SELECT name, (size*8)/1024 ‘Size in MB’

FROM sys.database_files 



As you can see only the
first data file was  expanded and the
other has still the initial size:


name                  Size
in MB

——————— ———–

TF1117                5

TF1117_log            1

TF1117_1              4

There is also
other methods of looking at the events of file autogrows. One possibility is to
create an Extended Events session and the other is to look into the default
trace file:





         CHARINDEX(‘\’, REVERSE([path])), 260)) + N’log.trc’

FROM    sys.traces

is_default = 1;








                        CASE EventClass       

                             WHEN 92 THEN ‘Data’      

                             WHEN 93 THEN ‘Log’  


FROM sys.fn_trace_gettable(@path, DEFAULT)

EventClass IN (92,93)

AND StartTime >‘2014-07-12’ AND
DatabaseName = N’TF1117′

ORDER BY   StartTime DESC;


After running the
query I can see the file was expanded and how long did the process take which
might be useful from the performance perspective.



Now it’s time to
turn on the flag 1117.



I dropped the
database and recreated it once again. Then I ran the queries and observed the
results. After loading the records I see that both files were evenly expanded:

name                  Size
in MB

——————— ———–

TF1117                5

TF1117_log            1

TF1117_1              5

I found also
information in the default trace. The query returned three rows. The last one
is connected to my first experiment when the TF was turned off.  The two rows shows that first file was
expanded by 1MB and right after that operation the second file was expanded,
too. This is what is this TF all about



  • RichB

    Aug 12, 2014 at 04:38 AM

    Interesting, but would be even more interesting if you had a compelling performance case demonstration scripted 🙂

  • RichB – I try to do that 🙂

  • Shane O'Neill

    Jul 12, 2017 at 07:09 AM

    Thanks for this.
    It took a surprisingly long time to find information about this TF effecting all databases on an instance.
    The demo was a welcome touch as well 🙂

Receive comment updates via RSS

Leave a Comment