All Products
Search
Document Center

ApsaraDB RDS:How do I view the storage capacity, storage that is used by databases, and storage that is used by tables of an ApsaraDB RDS for SQL Server instance?

Last Updated:Aug 05, 2024

This topic describes how to view the storage capacity, storage that is used by databases, and storage that is used by tables of an ApsaraDB RDS for SQL Server instance.

View the storage capacity of the RDS instance

Go to the Basic Information page of the RDS instance to view the storage capacity.

image

View the storage that is occupied by databases

  1. Connect to the RDS instance from a client. For more information, see Connect to an ApsaraDB RDS for SQL Server instance.

  2. View the storage that is occupied by a database.

    USE <Database name>;
    GO
    EXEC sp_spaceused @updateusage = N'TRUE';

    Parameter

    Description

    database_size

    The size of the database, including the sizes of data files and log files. The value is greater than the sum of the values of the reserved and unallocated space parameters.

    unallocated space

    The size of unallocated storage of the database.

    reserved

    The total size of storage allocated for the database.

    data

    The storage that is occupied by data.

    index_size

    The storage that is occupied by indexes.

    unused

    The storage that is allocated but is unused.

  3. View the storage that is occupied by all databases.

    USE master
    GO
    DECLARE @insSize TABLE(dbName sysname,checkTime VARCHAR(19),dbSize VARCHAR(50),logSize VARCHAR(50))
    INSERT INTO @insSize ( dbName, checkTime, dbSize, logSize )
    EXEC sp_msforeachdb 'select ''?'' dbName,CONVERT(VARCHAR(19),GETDATE(),120) checkTime,LTRIM(STR(SUM(CASE WHEN RIGHT(FILENAME,3)<>''ldf'' THEN convert (dec (15,2),size) * 8 / 1024 ELSE 0 END),15,2)+'' MB'') dbSize,  
                     LTRIM(STR(SUM(CASE WHEN RIGHT(FILENAME,3)=''ldf''  THEN convert (dec (15,2),size) * 8 / 1024 ELSE 0 END),15,2)+'' MB'') logSize from ?.dbo.sysfiles'
    SELECT * FROM @insSize ORDER BY CONVERT(DECIMAL,LTRIM(RTRIM(SUBSTRING(dbSize,1,LEN(dbSize)-2)))) DESC

    The result does not include the size of log files. You can execute the following statement to view the size of log files:

    DBCC SQLPERF(LOGSPACE);

View the storage that is occupied by tables in a database

  1. Connect to the RDS instance from a client. For more information, see Connect to an ApsaraDB RDS for SQL Server instance.

  2. View the storage that is occupied by a table in the database.

    USE <Database name>;
    GO
    EXEC sp_spaceused N'<Table name>';

  3. View the storage that is occupied by all tables in the database.

    USE <Database name>;
    GO
    DECLARE @tabSize TABLE (
        name NVARCHAR(100),
        rows CHAR(20),
        reserved VARCHAR(18),
        data VARCHAR(18),
        index_size VARCHAR(18),
        unused VARCHAR(18)
    );
    
    INSERT INTO @tabSize 
    EXEC sp_MSForEachTable '
    EXEC sp_spaceused ''?''';
    
    SELECT * 
    FROM @tabSize 
    ORDER BY CONVERT(INT, REPLACE(data, ''KB'', '''')) DESC, 2 DESC;

References