Refer to this topic to view space usage of RDS SQL Server instances, troubleshoot, and resolve full database disk space issues.
View storage usage
Method 1: Log on to the ApsaraDB RDS console and go to the Basic Information page of your RDS instance. In the Usage Statistics section of the page, view the overall storage usage of your RDS instance. The Usage Statistics section does not display the current or historical storage usage for various data types.

Method 2: Log on to the ApsaraDB RDS console and navigate to the Monitoring and Alerts page. On the Standard Monitoring tab, you can view both current and historical storage usage for various data types. For more information, see View standard monitoring information.

Method 3: Log on to the ApsaraDB RDS console and go to the instance details page of your RDS instance. In the left-side navigation pane, choose Autonomy Services > Storage Management. Then, view the storage usage of your RDS instance. The storage usage includes the percentages of used data storage and used log storage, the storage consumption trends, and the storage consumption for each of the top 10 databases and top 20 tables that consume the most storage resources. For more information, see Storage 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 storage usage of your RDS instance. For more information, see Connect to an ApsaraDB RDS for SQL Server instance by using SSMS.
The following commands are commonly used to view SQL Server database space usage information.
System view or statement
Description
sp_helpdbUsed to query the total storage space of each database. The total storage space of a database is equal to the total size of data files and log files in the database.
sp_spaceusedUsed to query the name, used storage space, and unallocated storage space of the current database.
DBCC SQLPERF(LOGSPACE)Used to query the total log storage and used log storage of each database.
DBCC SHOWFILESTATSUsed to query the total data storage and used data storage of the current database.
SELECT * FROM sys.master_filesUsed to query the total size of data files and the total size of log files in each database.
SELECT * FROM sys.dm_db_log_space_usageUsed to query the total log storage and used log storage of the current database. This statement is supported only for RDS instances that run SQL Server 2012 or later.
SELECT * FROM sys.dm_db_file_space_usageUsed to query the total data storage and used data storage of the current database. This statement is supported only for RDS instances that run SQL Server 2012 or later.
If the storage usage of your RDS instance is abnormally high, you must log on to the RDS console and go to the Monitoring And Alerts page of your RDS instance to view the storage usage for data files, log files, temporary files, and system files. Then, you can identify the type of file that consumes an abnormally increased amount of storage and evaluate whether you need to release storage or use methods to prevent an abnormal increase in storage consumption.
Reclaim and release data storage
Analysis
The total data storage, which is equal to the total size of data files, consists of allocated data storage and unallocated data storage:
The allocated data storage consists of used data storage and unused data storage. The unused data storage can be allocated only to new records in the same table or index. The unused data storage cannot be directly allocated to other database objects.
The unallocated data storage consists of extents that are not allocated. Each extent provides 64 KB of contiguous storage. The unallocated data storage is not associated with database objects. You can shrink data files to release the unallocated data storage.
In most cases, if the amount of your data continues to increase, the unallocated data storage is small. In this case, you cannot reclaim a large amount of data storage by shrinking data files. Before you shrink data files, we recommend that you optimize and reclaim the allocated data storage.
Reclaim data storage
You can use one of the following methods to reclaim the data storage:
Archive data files
Delete historical data files that are not frequently queried, migrate these data files to other RDS instances, or archive these data files. This reduces the amount of data that is stored on your RDS instance.
This method effectively mitigates increases in data storage consumption. However, this method has requirements for the database object structure and the logic of your application. This method also requires cooperation with application designers and developers.
Compress data files
If your RDS instance runs SQL Server 2016 or later or runs an SQL Server Enterprise Edition earlier than SQL Server 2016, the data compression feature is provided. This feature supports row compression and page compression. You can enable this feature on individual tables, indexes, or partitions. For more information, see Data Compression.
The data compression ratio ranges from 10% to 90% and varies based on the schema, column data types, and distribution of numerical values. SQL Server provides a dedicated stored procedure sp_estimate_data_compression_savings that can help you quickly evaluate how much data storage space can be saved by enabling compression on a specified table or index.
NoteTo modify the compression option settings of tables or indexes, you must run data definition language (DDL) operations. If you run these operations on large tables, the tables are locked for a long period of time. This may interrupt your workloads. We recommend that you modify the compression option settings during off-peak hours.
RDS SQL Server Enterprise instances can set the parameter ONLINE to ON, and then perform modification operations with minimal impact on normal business operations.
Data compression increases CPU overhead. You must evaluate the feasibility of data compression on your RDS instance based on your business requirements. We recommend that you enable the data compression feature only on large tables.
Defragment indexes
If the degree of fragmentation in an index is high, the underlying data of the index consumes an abnormally large amount of storage. In this case, you can defragment the index to reduce the amount of used data storage.
View the degree of fragmentation in indexes: Log on to the ApsaraDB RDS console and choose Autonomy Services > Performance Optimization. Then, click the Index Usage tab. On this tab, you can view the index fragmentation in various tables. In addition, you can view the suggestions that are proposed by the autonomy service to rebuild or reorganize indexes.
NoteThe degree of fragmentation in an index represents the percentage of pages whose logical ordering does not match the physical ordering inside the index. This percentage is different from the percentage of idle storage space in index pages. In normal cases, an index with a high degree of fragmentation is likely to be defragmented to reclaim storage space.
If you want to analyze the average percentage of idle storage per page in an index, you can query the
sys.dm_db_index_physical_statssystem view inSAMPLEDorDETAILEDmode. Then, you can view the values in theavg_page_space_used_in_percentcolumn of the returned result. For more information, see sys.dm_db_index_physical_stats (Transact-SQL). The system reads many index pages during queries. If you defragment indexes during queries, the performance of your RDS instance may decrease. We recommend that you defragment indexes during off-peak hours.
Rebuild an index
This method provides better optimization results and higher execution efficiency for high fragmentation rates. By default, the table is locked during execution. In the Enterprise Edition, you can set the parameter
ONLINEto ON to avoid long-term table locking.ImportantFor large indexes, the rebuild operation may cause a significant increase in database storage space and log size in a short period of time. Typically, before performing an index rebuild operation, your RDS instance needs to reserve at least twice the size of the index being rebuilt as available space. Therefore, make sure that your instance has sufficient available storage space.
View RDS instance storage space: Go to the Basic Information page of the RDS instance details page. In the Instance Resources section, view the total storage space size and used storage space size of the instance.
ALTER INDEX <IX_YourIndexName> ON <YourTableName> REBUILD WITH (ONLINE = ON);After the command is executed, the system will asynchronously recollect data in the background, which takes some time. You can click the Recollect button to manually collect the latest data, and after the data collection is complete, click Export Script to download it locally to confirm the index reclamation status.

Reorganize an index
This method is suitable if the degree of fragmentation is low. However, the optimization effectiveness is not as good as that of the index rebuilding method.
Shrink data files
If the available storage is still insufficient after you have tried all suggested solutions, you can use one of the following methods to release data storage:
If you shrink many data files on your RDS instance at a time, many transaction logs may be generated and your services may be blocked for a long period of time. We recommend that you use Method 1 to shrink a small number of data files at a time.
Method 1: Shrink data files in batches. We recommend that you shrink 5 GB of data files at a time. Sample code:
DECLARE @dbName NVARCHAR(128) = 'YourDatabaseName' -- Database name DECLARE @fileName NVARCHAR(128) -- Data file name DECLARE @targetSize INT = 1024 -- Target size (MB) DECLARE @shrinkSize INT = 5120 -- Size of data files that you shrink at a time (MB), we recommend 5GB at a time DECLARE @currentSize INT -- Current size DECLARE @sql NVARCHAR(500) DECLARE @waitTime INT = 10 -- Time to wait after each shrink operation in seconds -- Get data file name SELECT @fileName = name FROM sys.master_files WHERE database_id = DB_ID(@dbName) AND type_desc = 'ROWS' -- Loop shrinking WHILE 1 = 1 BEGIN -- Get current file size SELECT @currentSize = size/128 FROM sys.database_files WHERE name = @fileName -- Exit if the target size is reached IF @currentSize <= @targetSize BEGIN PRINT 'Shrink complete, current size: ' + CAST(@currentSize AS VARCHAR(20)) + 'MB' BREAK END -- Calculate the size after this shrink operation DECLARE @newSize INT = @currentSize - @shrinkSize IF @newSize < @targetSize SET @newSize = @targetSize -- Execute shrink operation SET @sql = 'DBCC SHRINKFILE (N''' + @fileName + ''', ' + CAST(@newSize AS VARCHAR(20)) + ')' PRINT 'Executing shrink: ' + @sql EXEC (@sql) -- Wait for a period of time before continuing PRINT 'Waiting ' + CAST(@waitTime AS VARCHAR(10)) + ' seconds before continuing...' WAITFOR DELAY '00:05:00' ENDMethod 2: Run the
DBCC SHRINKFILEcommand to shrink individual data files and release the unallocated data storage to the operating system. For more information, see Shrink a Database and DBCC SHRINKFILE (Transact-SQL).DBCC SHRINKFILE(<File ID>, <Expected file size after the shrink in MB>)
FAQ
Reclaim log storage
View used log storage
Reclaiming log storage is relatively simple. You can use the DBCC SQLPERF(LOGSPACE) command or the autonomy service to view the percentage of used log storage in the database log files. If the percentage of used storage is high, shrinking log files will have almost no effect. You can query the system view sys.databases and check the output information in the log_reuse_wait and log_reuse_wait_desc columns to determine why the space cannot be reclaimed.
For more information about the values in the log_reuse_wait and log_reuse_wait_desc columns, see sys.databases (Transact-SQL).
Shrink transaction logs
If your database server displays a "transaction log is full" message, you cannot shrink transaction logs through the console. You can manually execute SQL statements to handle this issue, but this approach carries risks. For more information, see Solutions for insufficient log space (only applicable in emergency situations). When log space is insufficient, we generally recommend that you first expand the disk capacity.
Attribute | Method 1: Shrink a single database (shrink only, no backup) | Method 2: Instance-level backup and shrink (back up first, then shrink) |
Scope | Single database | Entire instance |
Backup | No backup | The system automatically backs up all transaction logs. |
Storage reclamation speed | Quick | Slow. The system creates backups and then shrinks transaction logs. |
Scenarios | Logs are generated at a fast speed. The log storage must be reclaimed before the next instance-level full backup or incremental backup is created. | Log storage is sufficient. Global optimization is required. If you shrink transaction logs, a specific amount of log storage is occupied. |
Impact on other databases | No impact | The entire instance is affected. |
Procedure |
After the shrink operation is complete, you can go to the Monitoring And Alerts page of your RDS instance to view the latest log storage usage.

Reclaim temporary file storage
Analysis
The temporary file storage is the amount of storage that is used by the tempdb system database. The tempdb system database uses only the SIMPLE recovery model. In normal cases, the total size of log files in the tempdb system database is small. However, the total size of data files in the tempdb system database can significantly increase within a short period of time. For example, if you create many temporary tables, join large tables, or sort data, the total size of data files in the tempdb system database increases.
Solutions
Prevent storage consumption increases at the application level. For example, reduce unnecessary temporary tables, reduce queries that require the joins of large tables, and do not run large transactions.
Restart your RDS instance during off-peak hours. After the restart, the amount of storage that is used by the tempdb system database decreases to the size at the time when the instance was created.
Reclaim other file storage
Analysis
Other file storage refers to the space occupied by sqlserver.other_size, mastersize, modelsize, msdbsize, and other similar files. In most cases, these files are small. However, these files can consume a large amount of storage space in the following scenarios:
Many
errorlogfiles exist, and the error log file size has grown to several GB or even larger.Memory dump files are generated when severe exceptions occur.
Solutions
You can go to the Monitoring And Alerts page of your RDS instance and click the Standard Monitoring tab to view the storage occupied by these files. For more information about the metrics, see View standard monitoring information.

If
errorlogoccupies a large amount of storage, you can clear the error logs on the Log Management page. For more information, see Manage logs.NoteIf other files (such as
sqlserver.other_size) occupy too much space, please contact the helpdesk. They will help you identify the cause and resolve the issue.
Expand storage capacity
If the storage usage of your RDS instance is still abnormally high after you have tried all the suggested solutions, you can expand the storage capacity of the RDS instance. For more information, see Change instance specifications.
In the example shown above, the size of an extent is 64 KB. The total size of the data file is