You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/databases/shrink-tempdb-database.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
---
2
-
title: Shrink the tempdb database
2
+
title: Shrink the tempdb Database
3
3
description: Learn how to shrink the tempdb database by using Transact-SQL.
4
4
author: rwestMSFT
5
5
ms.author: randolphwest
6
-
ms.date: 07/25/2024
6
+
ms.date: 06/12/2025
7
7
ms.service: sql
8
8
ms.subservice: supportability
9
9
ms.topic: how-to
@@ -38,7 +38,7 @@ By default, the `tempdb` database is configured to autogrow as needed. Therefore
38
38
39
39
When [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] starts, `tempdb` is re-created by using a copy of the `model` database, and `tempdb` is reset to its last configured size. The configured size is the last explicit size that was set by using a file size changing operation such as `ALTER DATABASE` that uses the `MODIFY FILE` option or the `DBCC SHRINKFILE` or `DBCC SHRINKDATABASE` statements. Therefore, unless you have to use different values or obtain immediate resolution to a large `tempdb` database, you can wait for the next restart of the [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] service for the size to decrease.
40
40
41
-
You can shrink `tempdb` while `tempdb` activity is ongoing. However, you might encounter other errors such as blocking, deadlocks, and so on, that can prevent shrink from completing. Therefore, in order to make sure that a shrink of `tempdb` succeeds, we recommend that you do this while the server is in single-user mode or when you stop all `tempdb` activity.
41
+
You can shrink `tempdb` while `tempdb` activity is ongoing. However, you might encounter other errors such as blocking, deadlocks, and so on, that can prevent shrink from completing. Therefore, in order to make sure that a shrink of `tempdb` succeeds, we recommend that you do this while the server is in single-user mode, or when you stop all `tempdb` activity.
42
42
43
43
[!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] records only enough information in the `tempdb` transaction log to roll back a transaction, but not to redo transactions during database recovery. This feature increases the performance of `INSERT` statements in `tempdb`. Additionally, you don't have to log information to redo any transactions because `tempdb` is re-created every time that you restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)]. Therefore, it has no transactions to roll forward or to roll back.
44
44
@@ -47,7 +47,7 @@ For more information about managing and monitoring `tempdb`, see [Capacity plann
47
47
## Use the ALTER DATABASE command
48
48
49
49
> [!NOTE]
50
-
> This command operates only on the default `tempdb` logical files `tempdev` and `templog`. If more files are added to `tempdb`, you can shrink them after you restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] as a service. All `tempdb` files are re-created during startup. However, they are empty and can be removed. To remove additional files in `tempdb`, use the `ALTER DATABASE` command with the `REMOVE FILE` option.
50
+
> This command operates only on the default `tempdb` logical files `tempdev` and `templog`. If more files are added to `tempdb`, you can shrink them after you restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] as a service. All `tempdb` files are re-created during startup. However, these files are empty and can be removed. To remove additional files in `tempdb`, use the `ALTER DATABASE` command with the `REMOVE FILE` option.
51
51
52
52
This method requires you to restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)].
53
53
@@ -86,7 +86,7 @@ This method requires you to restart [!INCLUDE [ssnoversion-md](../../includes/ss
86
86
(NAME = 'templog', SIZE = <target_size_in_MB>);
87
87
```
88
88
89
-
1. Stop [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)]. To do this, press `Ctrl+C` at the Command Prompt window, restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] as a service, and then verify the size of the `tempdb.mdf` and `templog.ldf` files.
89
+
1. Stop [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)]. To do this, press `Ctrl+C` at the command prompt window, restart [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] as a service, and then verify the size of the `tempdb.mdf` and `templog.ldf` files.
90
90
91
91
## Use the DBCC SHRINKDATABASE command
92
92
@@ -95,7 +95,7 @@ This method requires you to restart [!INCLUDE [ssnoversion-md](../../includes/ss
95
95
1. Determine the space that is currently used in `tempdb` by using the `sp_spaceused` stored procedure. Then, calculate the percentage of free space that is left for use as a parameter to `DBCC SHRINKDATABASE`. This calculation is based on the desired database size.
96
96
97
97
> [!NOTE]
98
-
> In some cases, you might have to execute `sp_spaceused @updateusage = true` to recalculate the space that is used and to obtain an updated report. For more information, see [sp_spaceused](../system-stored-procedures/sp-spaceused-transact-sql.md).
98
+
> In some cases, you might have to execute `sp_spaceused @updateusage = true` to recalculate the space that is used, and to obtain an updated report. For more information, see [sp_spaceused](../system-stored-procedures/sp-spaceused-transact-sql.md).
99
99
100
100
Consider the following example:
101
101
@@ -140,14 +140,14 @@ If `tempdb` is being used, and if you try to shrink it by using the `DBCC SHRINK
140
140
Server: Msg 8909, Level 16, State 1, Line 1 Table error: Object ID 0, index ID -1, partition ID 0, alloc unit ID 0 (type Unknown), page ID (6:8040) contains an incorrect page ID in its page header. The PageId in the page header = (0:0).
141
141
```
142
142
143
-
This error doesn't indicate any real corruption in `tempdb`. However, there might be other reasons for physical data corruption errors like error 8909, and that those reasons include I/O subsystem problems. Therefore, if the error happens outside shrink operations, you should do more investigation.
143
+
This error doesn't indicate any real corruption in `tempdb`. However, there might be other reasons for physical data corruption errors like error 8909, and that those reasons include I/O subsystem problems. Therefore, if the error happens outside shrink operations, you should investigate further.
144
144
145
145
Although an 8909 message is returned to the application or to the user who is executing the shrink operation, the shrink operations don't fail.
146
146
147
147
## Related content
148
148
149
149
-[Considerations for the autogrow and autoshrink settings in SQL Server](/troubleshoot/sql/admin/considerations-autogrow-autoshrink)
150
-
-[Database Files and Filegroups](database-files-and-filegroups.md)
150
+
-[Database files and filegroups](database-files-and-filegroups.md)
0 commit comments