The space usage of an RDS for SQL Server instance is a key metric to monitor. Insufficient storage space can cause serious problems, such as the database failing to write data or create backups. Additionally, scaling out storage space can be time-consuming. This topic describes how to view space usage and troubleshoot space-related issues.
View space usage
Method 1: Go to the Basic Information page of the instance to view space usage. This page shows only the total current space usage. It does not provide details about the space occupied by different data types or historical usage information.

Method 2: Go to the Monitoring and Alerts page of the instance. On the Standard Monitoring page, you can view the disk space occupied by different data types and their historical trends. For more information about the metrics, see View standard monitoring.

Method 3: Go to the Autonomy Services > Storage Management page in the console to view more detailed space usage information. This includes a comparison of data and log space usage, historical trends, and space allocation details for top databases and tables. For more information, see Space Management.
NoteYour RDS instance does not run SQL Server 2008 R2 with cloud disks.

Method 4: Use a client tool, such as SQL Server Management Studio (SSMS), to view the space usage information of the instance. For more information, see Connect to an RDS for SQL Server instance using an SSMS client.
The following table lists common commands to view space usage information for a SQL Server database.
System view or command
Description
sp_helpdbView the total space size (sum of data file and log file sizes) for each database.
sp_spaceusedView the name, used space size, and unallocated space size of the current database.
DBCC SQLPERF(LOGSPACE)View the total log file size and the actual used log space for each database.
DBCC SHOWFILESTATSView the total data file size and the actual used data space for all data files in the current database.
SELECT * FROM sys.master_filesView the size of data and log files for each database.
SELECT * FROM sys.dm_db_log_space_usageView the total log space and the actual used log space of the current database. This command applies only to SQL Server 2012 and later versions.
SELECT * FROM sys.dm_db_file_space_usageView the total data file space and the actual used data space of the current database. This command applies only to SQL Server 2012 and later versions.
If the instance has high space usage, go to the Monitoring and Alarms page in the RDS console. Check the space usage of data, logs, temporary files, and other files to identify which file type is growing too quickly. Then, evaluate whether you can release space or prevent rapid growth. For a detailed analysis and solutions, see the following sections.
Reclaim and release data space
Analyze the cause
The total data space is the sum of all data file sizes and consists of two parts: allocated space and unallocated space.
Allocated space includes used and unused space. Unused space can be allocated only to new records in the same table or index and cannot be used directly by other database objects.
Unallocated space consists of completely unallocated extents. Each extent is 64 KB of contiguous space. Unallocated space is not associated with any database object. You can release this space by shrinking files.
If the data volume grows continuously, the unallocated space is typically small. In this scenario, shrinking files directly is not effective. You must first optimize and reclaim the allocated space before you consider shrinking the files.
Reclaim data space
The following methods are commonly used to reclaim data space:
Archive data
Delete infrequently used data, such as old historical data, from the database. You can also migrate the data to other database instances or archive it in other formats. This method directly reduces the data volume and the used data space.
This method is effective for controlling data space growth but requires specific designs for database objects and application logic. It also requires cooperation from application designers and developers.
Compress data
Instances that run SQL Server 2016 or later and Enterprise instances that run a version earlier than 2016 have a built-in data compression feature. You can enable row or page compression on a single table, index, or partition. For more information, see Data Compression.
The data compression ratio varies widely. It depends on the table schema, column data types, and value distribution. The ratio can range from 10% to 90%. SQL Server provides a dedicated stored procedure, sp_estimate_data_compression_savings, to help you quickly estimate the storage savings that result from enabling compression on a specific table or index.
NoteModifying compression settings on a table or index is a Data Definition Language (DDL) operation. For large tables, this operation can cause long-term table locks and affect your business. You should perform this operation during off-peak hours.
For an RDS for SQL Server Enterprise instance, you can set the ONLINE parameter to ON. Then, you can execute the modification. This has a minimal impact on your business.
Data compression increases CPU overhead. You should evaluate the impact as needed. Enable data compression only on large tables.
Defragment indexes
A high index fragmentation rate can slow down queries and increase data storage usage. Defragmenting indexes can improve query speed and release unnecessary storage space.
View index fragmentation rate: In the RDS console, go to the Autonomy Services > Performance Optimization page. Click the Index Usage tab to view the index fragmentation rate for each table. The autonomy service provides suggestions to rebuild or reorganize indexes.
NoteThe index fragmentation rate is the percentage of logically contiguous index pages that are not physically contiguous. This is different from the percentage of free space in index pages. However, indexes with high fragmentation rates are also likely to have a high percentage of reclaimable space.
To analyze the average free space percentage within the pages of an index, you can query the
sys.dm_db_index_physical_statssystem view inSAMPLEDorDETAILEDmode. Then, check the value in theavg_page_space_used_in_percentcolumn of the result set. For more information, see sys.dm_db_index_physical_stats (Transact-SQL). This query reads many index pages and may affect database performance. You should perform this operation during off-peak hours.
Index rebuild operation
This operation provides better optimization and is more efficient for indexes with high fragmentation rates. By default, a rebuild operation locks the corresponding table. For Enterprise instances, you can set the
ONLINEparameter to ON to avoid long-term table locks.ImportantFor large indexes, a rebuild operation can cause a significant short-term increase in database storage space and log size. Before you rebuild an index, make sure the RDS instance has free storage space that is at least twice the size of the index that is being rebuilt.
View RDS instance storage space: Go to the Basic Information page of the RDS instance. In the Instance Resources section, you can view the total and used storage space of the instance.
If the free space is insufficient, you can perform a storage scale-out. After the scale-out is successful, you do not need to restart the instance. The system automatically applies the new space, and the change takes effect immediately.
ALTER INDEX <IX_YourIndexName> ON <YourTableName> REBUILD WITH (ONLINE = ON);After the command is executed, the system asynchronously collects index statistics again in the background. This process takes some time. Therefore, the fragmentation rate displayed on the console page may not update immediately. You can click the Recollect button to manually collect the latest data. After data collection is complete, you can click Export Script to download the script to your local machine and confirm whether the index fragmentation rate has decreased.

Index reorganize operation
This operation is more efficient for indexes with low fragmentation rates, but its optimization effect is not as significant as a rebuild.
Shrink data files
The data space reclamation methods described in the previous section can usually reduce data space usage effectively. If the instance space is still under pressure, you can use one of the following two methods:
A single, large-scale shrink operation on a SQL Server database can cause significant transaction log growth and long-term blocking. Use Method 1 to shrink the file in a loop of mini-batches.
Method 1: Shrink the data file in a loop of mini-batches. We recommend that you shrink the file by 5 GB in each iteration. The following is an example:
-- This script applies only to SQL Server 2012 and later versions. Specify the following parameters before use. DECLARE @dbName NVARCHAR(128) = 'YourDBName' -- Database name DECLARE @fileName NVARCHAR(128) -- Data file name DECLARE @targetSize INT = 2000 -- Target size (MB) DECLARE @shrinkSize INT = 5120 -- The size to shrink in each loop iteration (MB). We recommend 5 GB. DECLARE @currentSize INT -- Current size DECLARE @freeSize INT -- Free space size DECLARE @usedSize INT -- Used space size DECLARE @sql NVARCHAR(500) DECLARE @waitTime INT = 10 -- Wait time after each shrink operation (seconds) -- Get the data file name SELECT @fileName = name FROM sys.master_files WHERE database_id = DB_ID(@dbName) AND type_desc = 'ROWS' -- Shrink in a loop WHILE 1 = 1 BEGIN -- Get the current size, free space size, and used space size DECLARE @sql0 NVARCHAR(MAX) = N' USE [' + @dbName + ']; SELECT @currentSize = (SUM(total_page_count) * 1.0 / 128), @freesize = (SUM(unallocated_extent_page_count) * 1.0 / 128) FROM sys.dm_db_file_space_usage WHERE database_id = DB_ID();' EXEC sp_executesql @sql0, N'@currentSize INT OUTPUT, @freesize INT OUTPUT', @currentSize OUTPUT, @freesize OUTPUT PRINT 'Current size:' + CAST(@currentSize AS VARCHAR(10)) + 'MB' PRINT 'Free size:' + CAST(@freeSize AS VARCHAR(10)) + 'MB' set @usedSize=@currentSize - @freeSize PRINT 'Used size:' + CAST(@usedSize AS VARCHAR(10)) + 'MB' -- Check if the target size is smaller than the used space size IF @targetSize <= @usedSize BEGIN PRINT 'The target size is too small. Specify a new size. The target size cannot be smaller than: ' + CAST(@usedSize AS VARCHAR(20)) + 'MB' BREAK END -- Exit if the target size is reached IF @currentSize <= @targetSize BEGIN PRINT 'Shrink completed. Current size: ' + CAST(@currentSize AS VARCHAR(20)) + 'MB' BREAK END -- Calculate the new size after this shrink operation DECLARE @newSize INT = @currentSize - @shrinkSize IF @newSize < @targetSize SET @newSize = @targetSize -- Execute the shrink operation SET @sql = 'USE [' + @dbName + '];DBCC SHRINKFILE (N''' + @fileName + ''', ' + CAST(@newSize AS VARCHAR(20)) + ')' PRINT 'Executing shrink: ' + @sql EXEC (@sql) -- Wait for a period and then continue PRINT 'Waiting ' + CAST(@waitTime AS VARCHAR(10)) + ' seconds to continue...' WAITFOR DELAY '00:00:10' ENDMethod 2: Execute the
DBCC SHRINKFILEcommand to directly shrink a single data file. This command releases the unallocated space in the data file to the operating system. For more information, see Shrink a Database and DBCC SHRINKFILE (Transact-SQL).DBCC SHRINKFILE(<File ID>, <Target size in MB>)
FAQ
Reclaim log space
View used log space
Reclaiming log space is relatively simple. You can use the DBCC SQLPERF(LOGSPACE) command or DAS to view the percentage of used space in the database log file. If the percentage of used space is high, shrinking the log file has little effect. You can query the sys.databases system view. Check the output of the log_reuse_wait and log_reuse_wait_desc columns to determine why the space cannot be reclaimed.
For more information about the values of log_reuse_wait and log_reuse_wait_desc, see sys.databases (Transact-SQL).
Shrink transaction logs
If your database server indicates that the transaction log is full, you cannot shrink the transaction log from the console. You can manually execute an SQL statement to handle this issue. However, this solution carries risks. For more information, see Solution for insufficient log space (for emergency use only). If the log space is insufficient, we recommend that you first scale out the disk.
Feature | Solution 1: Shrink a single database (shrink only, no backup) | Solution 2: Back up and shrink at the instance level (back up first, then shrink) |
Scope | Single database | Entire instance |
Backup | No backup | Automatically backs up all transaction logs |
Space reclamation speed | Fast | Slower (requires backup before shrinking) |
Scenarios | Fast log growth, cannot wait for the next instance-level full or incremental backup (urgent space reclamation needed) | Sufficient log space (shrinking transaction logs consumes some log space), global optimization needed |
Impact on other databases | No impact | Affects the entire instance |
Operation |
After the shrink operation is complete, you can go to the Monitoring and Alarms page of the RDS instance to view the latest log space status.

Reclaim temporary file space
Cause analysis
The tempdb database is a system database in SQL Server that stores temporary data. The data file space in tempdb is frequently used in many scenarios, such as:
User objects: Temporary tables created by users.
Internal objects: Temporary tables generated internally by SQL Server.
Version store: When snapshot isolation or read committed snapshot is enabled for a database, versioning information is stored in
tempdb.
If certain operations, such as long-running transactions, the creation of many temporary tables, or snapshot isolation, use a large amount of space, the data file can become bloated. This means the file size grows significantly beyond its normal range. For more information, see the official Microsoft tutorial for the tempdb database.
Solutions
An RDS for SQL Server database contains data files and log files. The methods to reclaim space for each are as follows:
Reclaiming data file space
If the data file space for tempdb grows large, using the SHRINKFILE command to shrink it is not very effective. Instead, you can restart the instance during off-peak hours to release tempdb space, as described in the official Microsoft tutorial (Shrink the tempdb database).
You can use the following solutions to analyze the space usage of tempdb data files:
Reclaiming log file space
If the log file space for tempdb grows large, it is usually because a long-running transaction prevents the log from being truncated. You can reclaim the space as follows:
Check the log reuse wait type in the
log_reuse_wait_descfield ofsys.database. If the log reuse wait type isACTIVE_TRANSACTION, a long-running transaction exists.Identify which long-running transactions are running in the
tempdbdatabase. After you end the long-running transactions, you can useSHRINKFILEto shrink the log file.
You can use the following solutions to analyze the space usage of tempdb log files:
First, check the status of the database log file.
In the execution results, check the tempdb log space status. If
LogReuseWaitDescriptionisNOTHING, you can shrink the log file directly withSHRINKFILE. If the value is notNOTHING, such as the common valueACTIVE_TRANSACTION, an active long-running transaction exists. You must end the long-running transaction before you shrink the log file withSHRINKFILE.SELECT name AS [DatabaseName], recovery_model_desc AS [RecoveryModel], log_reuse_wait_desc AS [LogReuseWaitDescription] FROM sys.databases;
Tempdb log file growth is often caused by active long-running transactions. You can use the following SQL command to check for the longest-running transaction in the tempdb database and decide whether to end it:
USE tempdb; GO DBCC OPENTRAN; GOAs shown in the following figure, note the session ID (SPID) and the transaction start time (Start time):

Next, you can check what the session is doing and its status. You can use the session ID from the previous step:
SELECT * FROM sys.sysprocesses WHERE spid = xxx;--spid is the SPID from the previous stepFor example:

If the session status is
sleeping, you can use the following SQL command to check the executed statement:DBCC INPUTBUFFER(xxx); --xxx is the session ID (spid) from the previous stepThe following figure shows an example.

Reclaim other file space
Analyze the cause
Other file space refers to the space that is occupied by files such as sqlserver.other_size, mastersize, modelsize, and msdbsize. These files are usually small, but in some cases, they can become very large. For example:
There are many error logs (
errorlog), and the error log file size grows to several gigabytes or even larger.Memory dump files are automatically generated during critical exceptions.
Solutions
Go to the Standard Monitoring tab on the Monitoring and Alarms page of the RDS instance to view the space that is occupied by these files. For more information about the metrics, see View standard monitoring.

If
errorlogoccupies a large amount of space, you can go to the Log Management page to clear the error logs. For more information, see Manage logs.NoteIf other files, such as
sqlserver.other_size, occupy too much space, you can contact technical support. They will help you identify the cause and resolve the issue.
Scale out storage space
If the space usage of your RDS instance is high and you cannot effectively reduce it using the preceding methods, you must promptly scale out the instance storage space. For more information, see Change instance specifications.
In the preceding figure, the size of an extent is 64 KB. The total size of the data file is 









