Shrinking Databases

Scenarios

You can use a stored procedure to shrink the size of the data and log files in a specified database.

Prerequisites

An RDS Microsoft SQL Server DB instance has been connected. Connect to the DB instance through the Microsoft SQL Server client. For details, see Connecting to a DB Instance Through a Public Network.

Procedure

  1. Run the following command to shrink the database:

    EXEC [master].[dbo].[rds_shrink_database] @DBName='myDbName';

    Table 1 Parameter description

    Parameter

    Description

    myDbName

    Name of the database to be shrunk. If this parameter is not specified, all databases are shrunk by default.

  2. After the command is successfully executed, the following information is displayed:

    HW_RDS_Process_Successful: Shrink Database Done.

Example

  1. Run the following command to shrink the dbtest2 database:

    EXEC [master].[dbo].[rds_shrink_database] @DBName = 'dbtest2';

    The command output is as follows.

  2. Run the following command to shrink all databases:

    EXEC [master].[dbo].[rds_shrink_database];