SQL Server – Managing tempdb Datafiles

sql servertempdb

SQL newbie here, trying to understand how tempdb work when there is more than one datafile.
To keep this simple, let's assume the server has three tempdb datafiles, each 10GB, totaling 30GB and are all configured not to auto grow. If a user query were large enough to require 25GB of tempdb, would it:
A: fail
B: fill the first datafile then the second and into the third
C: randomly spread the usage across all three datafiles
D: something else entirely? If so, what is that something else?

Any insight into this is greatly appreciated.

Best Answer

It's a mix of C and D, depending on the free space in each of your tempdb files.

SQL Server uses a Proportional Fill algorithm to determine which data file should be used for any given write. Paul Randall discusses this in detail here.

Provided that your tempdb data files have roughly the same amount of free space, writes will be performed in a round robin fashion (one extent at a time).