Changing Custom Database Names
You can use a stored procedure to change a custom database name.
- An RDS Microsoft SQL Server DB instance has been connected. For details about how to connect to a DB instance, see Connecting to a DB Instance Through a Public Network.
- For primary/standby DB instances, you need to run the following command to remove database mirroring between them:
alter database [dbname] set partner off
- After the primary database name is changed, the system will automatically establish mirroring relationship.
If you do not remove database mirroring for primary/standby DB instances and attempt to change the primary database name, the system displays the following information:
Database database name is on mirroring_state.
- For a DB instance whose DB engine version is 2017 Enterprise Edition, if the database to be renamed is added to the [AG-RDS-YUN] availability group, you must remove the database from the availability group before renaming it. For details, see Removing a Custom Database from an Availability Group.
- System database names cannot be changed. If you attempt to change the name of a system database, the system displays the following information:
Error DBName_Source or DBName_Target. Please can not include in ('msdb','master','model','tempdb','rdsadmin','resource') .
- The new database name must be unique. If the new database name already exists, the system displays the following information:
Database database name already exists. Cannot rename database with the same name.
Run the following command to change a custom database name:
exec msdb.dbo.rds_rename_database N'oldname',N'newname';
- oldname indicates the original database name.
- newname indicates the new database name.
For example, to change a database name from ABC to XYZ, run the following command:
exec msdb.dbo.rds_rename_database N'ABC',N'XYZ';
The database name 'XYZ' has been set.
After the database name is changed, the system will automatically perform a full backup.