Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit f3be528

Browse files
authored
Merge pull request #21943 from WilliamDAssafMSFT/20220504-shrink-wlp-dallas
20220504 Shrink WLP for SQL 2022
2 parents 42da4fb + a42a4fd commit f3be528

4 files changed

Lines changed: 253 additions & 123 deletions

File tree

docs/relational-databases/databases/shrink-a-database.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: "Shrink a Database"
2+
title: "Shrink a database"
33
description: Learn how to shrink a database by using Object in SQL Server by using SQL Server Management Studio or Transact-SQL.
44
ms.custom: FY22Q2Fresh
5-
ms.date: "12/16/2021"
5+
ms.date: "05/24/2022"
66
ms.prod: sql
77
ms.prod_service: "database-engine, sql-database"
88
ms.reviewer: ""
@@ -20,7 +20,7 @@ author: WilliamDAssafMSFT
2020
ms.author: wiassaf
2121
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
2222
---
23-
# Shrink a Database
23+
# Shrink a database
2424
[!INCLUDE [SQL Server Azure SQL Database](../../includes/applies-to-version/sql-asdb.md)]
2525
This article describes how to shrink a database in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using Object Explorer in [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
2626

@@ -38,17 +38,21 @@ monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||
3838

3939
- Consider the following information when you plan to shrink a database:
4040

41-
- A shrink operation is most effective after an operation that creates lots of unused space, such as a truncate table or a drop table operation.
41+
- A shrink operation is most effective after an operation that creates a large amount of unused storage space, such as a large DELETE statement, truncate table, or a drop table operation.
4242

43-
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database repeatedly and notice that the database size grows again, this indicates that the space that was shrunk is required for regular operations. In these cases, repeatedly shrinking the database is a wasted operation, and likely created the need for autogrowth events to reclaim the space, hindering performance.
43+
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database repeatedly and notice that the database size grows again, this indicates that the free space is required for regular operations. In these cases, repeatedly shrinking the database is a wasted operation. Autogrow events necessary to grow the database file(s) a hinder performance.
4444

4545
- A shrink operation does not preserve the fragmentation state of indexes in the database, and generally increases fragmentation to a degree. This is another reason not to repeatedly shrink the database.
4646

4747
- Unless you have a specific requirement, do not set the AUTO_SHRINK database option to ON.
4848

4949
## <a name="Security"></a><a name="Permissions"></a> Permissions
5050
Requires membership in the **sysadmin** fixed server role or the **db_owner** fixed database role.
51-
51+
52+
## Remarks
53+
54+
Shrink operations in progress can block other queries on the database, and can be blocked by queries already in progress. Introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], shrink database operations have a WAIT_AT_LOW_PRIORITY option. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. If a new shrink operation in WAIT_AT_LOW_PRIORITY mode cannot obtain the necessary locks due to a long-running query already in progress, the shrink operation will eventually time out after one minute and quietly exit, preventing other queries from being blocked. For more information, see [DBCC SHRINKDATABASE](../../t-sql/database-console-commands/dbcc-shrinkdatabase-transact-sql.md).
55+
5256
## <a name="SSMSProcedure"></a> Use SQL Server Management Studio
5357

5458
#### Shrink a database
@@ -92,12 +96,16 @@ monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||
9296

9397
Data that is moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking. For more information, see [Rebuild an index](../../relational-databases/indexes/reorganize-and-rebuild-indexes.md#rebuild-an-index).
9498

95-
## Next steps
96-
- [Shrink a File](../../relational-databases/databases/shrink-a-file.md)
99+
## See also
100+
101+
- [Considerations for the autogrow and autoshrink settings in SQL Server](/troubleshoot/sql/admin/considerations-autogrow-autoshrink)
102+
- [Database Files and Filegroups](../../relational-databases/databases/database-files-and-filegroups.md)
97103
- [sys.databases &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md)
98104
- [sys.database_files &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md)
99-
- [DBCC &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-transact-sql.md)
105+
106+
## Next steps
107+
108+
- [DBCC SHRINKDATABASE &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-shrinkdatabase-transact-sql.md)
100109
- [DBCC SHRINKFILE &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md)
101-
- [Database Files and Filegroups](../../relational-databases/databases/database-files-and-filegroups.md)
102-
103-
110+
- [Delete Data or Log Files from a Database](../../relational-databases/databases/delete-data-or-log-files-from-a-database.md)
111+
- [Shrink a file](../../relational-databases/databases/shrink-a-file.md)

docs/relational-databases/databases/shrink-a-file.md

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: "Shrink a File | Microsoft Docs"
2+
title: "Shrink a file"
33
description: Learn how to shrink a data or log file in SQL Server by using SQL Server Management Studio or Transact-SQL.
44
ms.custom: ""
5-
ms.date: "03/14/2017"
5+
ms.date: "05/24/2022"
66
ms.prod: sql
77
ms.prod_service: "database-engine"
88
ms.reviewer: ""
@@ -17,45 +17,36 @@ helpviewer_keywords:
1717
- "reducing file size"
1818
- "size [SQL Server], files"
1919
- "file size [SQL Server]"
20-
ms.assetid: ce5c8798-c039-4ab2-81e7-90a8d688b893
2120
author: WilliamDAssafMSFT
2221
ms.author: wiassaf
22+
monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
2323
---
24-
# Shrink a File
24+
# Shrink a file
2525
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
26-
This topic describes how to shrink a data or log file in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
26+
27+
This article describes how to shrink a data or log file in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
2728

2829
Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the front of the file. When enough free space is created at the end of the file, data pages at end of the file can be deallocated and returned to the file system.
2930

30-
**In This Topic**
31-
32-
- **Before you begin:**
33-
34-
[Limitations and Restrictions](#Restrictions)
35-
36-
[Recommendations](#Recommendations)
37-
38-
[Security](#Security)
39-
40-
- **To shrink a data or log file, using:**
41-
42-
[SQL Server Management Studio](#SSMSProcedure)
43-
44-
[Transact-SQL](#TsqlProcedure)
45-
46-
## <a name="BeforeYouBegin"></a> Before You Begin
47-
4831
### <a name="Restrictions"></a> Limitations and Restrictions
4932

5033
- The primary data file cannot be made smaller than the size of the primary file in the model database.
5134

5235
### <a name="Recommendations"></a> Recommendations
36+
37+
- A shrink operation is most effective after an operation that creates a large amount of unused storage space, such as a large DELETE statement, truncate table, or a drop table operation.
38+
39+
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database file repeatedly and notice that the database size grows again, this indicates that the free space is required for regular operations. In these cases, repeatedly shrinking the database file is a wasted operation. Autogrow events necessary to grow the database file a hinder performance.
5340

5441
- Data that is moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking.
55-
56-
### <a name="Security"></a> Security
57-
58-
#### <a name="Permissions"></a> Permissions
42+
43+
- Unless you have a specific requirement, do not set the AUTO_SHRINK database option to ON.
44+
45+
## Remarks
46+
47+
Shrink operations in progress can block other queries on the database, and can be blocked by queries already in progress. Introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], shrink file operations have a WAIT_AT_LOW_PRIORITY option. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. If a new shrink operation in WAIT_AT_LOW_PRIORITY mode cannot obtain the necessary locks due to a long-running query already in progress, the shrink operation will eventually time out after one minute and quietly exit, preventing other queries from being blocked. For more information, see [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md).
48+
49+
### <a name="Security"></a><a name="Permissions"></a>Permissions
5950
Requires membership in the **sysadmin** fixed server role or the **db_owner** fixed database role.
6051

6152
## <a name="SSMSProcedure"></a> Using SQL Server Management Studio
@@ -66,7 +57,7 @@ ms.author: wiassaf
6657

6758
2. Expand **Databases** and then right-click the database that you want to shrink.
6859

69-
3. Point to **Tasks**, point to **Shrink**, and then click **Files**.
60+
3. Point to **Tasks**, point to **Shrink**, and then select **Files**.
7061

7162
**Database**
7263
Displays the name of the selected database.
@@ -117,25 +108,31 @@ ms.author: wiassaf
117108

118109
Selecting this option moves all data from the specified file to other files in the filegroup. The empty file can then be deleted. This option is the same as executing DBCC SHRINKFILE with the EMPTYFILE option.
119110

120-
9. Click **OK**.
111+
9. Select **OK**.
121112

122113
## <a name="TsqlProcedure"></a> Using Transact-SQL
123114

124115
#### To shrink a data or log file
125116

126117
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
127118

128-
2. From the Standard bar, click **New Query**.
119+
2. From the Standard bar, select **New Query**.
129120

130-
3. Copy and paste the following example into the query window and click **Execute**. This example uses [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md) to shrink the size of a data file named `DataFile1` in the `UserDB` database to 7 MB.
121+
3. Copy and paste the following example into the query window and select **Execute**. This example uses [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md) to shrink the size of a data file named `DataFile1` in the `UserDB` database to 7 MB.
131122

132123
[!code-sql[DBCC#DBCC_SHRINKFILE1](../../relational-databases/databases/codesnippet/tsql/shrink-a-file_1.sql)]
133124

134-
## See Also
135-
[DBCC SHRINKDATABASE &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-shrinkdatabase-transact-sql.md)
136-
[Shrink a Database](../../relational-databases/databases/shrink-a-database.md)
137-
[Delete Data or Log Files from a Database](../../relational-databases/databases/delete-data-or-log-files-from-a-database.md)
138-
[sys.databases &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md)
139-
[sys.database_files &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md)
140-
141-
125+
## See also
126+
127+
- [Considerations for the autogrow and autoshrink settings in SQL Server](/troubleshoot/sql/admin/considerations-autogrow-autoshrink)
128+
- [Database Files and Filegroups](../../relational-databases/databases/database-files-and-filegroups.md)
129+
- [sys.databases &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md)
130+
- [sys.database_files &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md)
131+
- [FILE_ID &#40;Transact-SQL&#41;](../../t-sql/functions/file-id-transact-sql.md)
132+
133+
## Next steps
134+
135+
- [DBCC SHRINKDATABASE &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-shrinkdatabase-transact-sql.md)
136+
- [DBCC SHRINKFILE &#40;Transact-SQL&#41;](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md)
137+
- [Delete Data or Log Files from a Database](../../relational-databases/databases/delete-data-or-log-files-from-a-database.md)
138+
- [Shrink a database](../../relational-databases/databases/shrink-a-database.md)

0 commit comments

Comments
 (0)