You are on page 1of 4

Srinivas Merugu

www.linkedin.com/in/srinivas-merugu-dba-azure

TEMPDB file full Issue

Find below solutions for TEMPDB file full Issue

1. Firstly we have to check which file is full. Data File Full Or Log File Full
and troubleshoot according that
Use tempdb
Go
sp_spaceused

OR
SELECT SUM(unallocated_extent_page_count) AS [free pages],
(SUM(unallocated_extent_page_count)*1.0/128) AS [free space in MB]
FROM sys.dm_db_file_space_usage;

Then find out which transaction is occupying more space in Tempdb.


2. Increase the initial size of temp DB if free space on drive
3. Increase the auto growth of file (Either In MB or percentage) if disabled.
4. Add NDF file from another/same drive. Once issue resolved then shrink
the file and remove newly added file from Database.
5. Generally if Tempdb gets full it may not allow new connections through

ssms.
➢ Try to connect it through query analyzer
➢ check for the log-reuse_wait_desc column of Tempdb Database
using syntax
Select [name], log_reuse_wait_desc from sys.databases where
name =’Tempdb’

1
Srinivas Merugu
www.linkedin.com/in/srinivas-merugu-dba-azure

➢ most common issue for this is long running active transactions,


the log_reuse_desc column will be ACTIVE _TRANSCATION.
then find out the oldest active transaction or open transaction by
DBCC OPENTRAN (‘TEMPDB’)

➢ And check what spid is doing using DBCC INPUT BUFFER


(SPID)
➢ if it is long running query, try to kill it using {kill spid]
➢ If there are no long running queries then issue checkpoint by [use
Tempdb checkpoint]
➢ This will flushes out the committed transactions
➢ Next sql server will respond normally and you need to shrink the
log/data file.

6. Check any open transactions are running or not


Use TempDB
DBCC opentran
If any open transactions are running then will not allow the shrink the
file.
If find any open transaction due to Tempdb getting full so contact with
the respective team and inform them about the transaction. Please don’t
kill any transaction without the approval of application team.

7. Check active transactions


We have to check with that which transactions are running and any
blockings with the below query.
select * from sys.sysprocesses where dbid = 2

2
Srinivas Merugu
www.linkedin.com/in/srinivas-merugu-dba-azure
OR
select * from sys.dm_exec_requests where session_id > 50
OR
Sp_who2 or sp_who2 active
If any transaction is not running then log file will be shrink
DBCC shrinkdb(‘tempdb’,’size’)

8. Try to shrink the Data File of Tempdb (if no OPEN transactions are in
progress).

Here first you have to verify the tempdb files location by using the below
command.
Use Tempdb
sp_helpfile or sp_helpdb ‘Tempdb’

After that you can use the below query to shrink the log or data file.
Note: You can shrink the tempdb data file for production server during
non-business hours (advisable).
USE [tempdb]
DBCC SHRINKFILE (N'templog' , 0)
Or
USE [tempdb]
DBCC SHRINKFILE (N'tempdev' , 8)
If we have multiple datafiles and shrink all files in single query window
in chunk basis.
9. If you are not able to release space from TempDB because entire Space in
TempDB will be unallocated space, Try the below T-SQL
USE TempDB
GO
DBCC FREEPROCCACHE /*Clears the procedure cache*/
Command will clear the procedure cache in memory. There is a risk involved with this, it can affect
next procedures to be reparsed and compiled. Also it might not give accurate results for DMV's.

3
Srinivas Merugu
www.linkedin.com/in/srinivas-merugu-dba-azure

DBCC DROPCLEANBUFFERS /*Forces all dirty pages for the current database to be written to disk
and cleans the buffers*/
DBCC FREESYSTEMCACHE ('ALL') /*Releases all unused cache entries from all caches*/

DBCC FREESESSIONCACHE /*Flushes the distributed query connection cache*/


CHECKPOINT /*Writes all dirty pages for the current database to disk*/

10. Request wintel team to add more space.

11. Final option is restart the instance once got approval . So new TempDB
will be creating.
Start->run->configuration manager->select services->Right click on
instance->restart.

You might also like