With Cloud SQL for SQL Server having HA enabled and a read replica, could you please provide guidance on how to remove or alter a database in the primary instance?
You can alter or remove a database in the primary instance, even if you have High Availability (HA) and read replicas enabled.
Access the Google Cloud Console: Start by logging into your Google Cloud Console.
Navigate to the Cloud SQL Instances page: Here, you'll see a list of all your Cloud SQL instances.
Select the relevant instance: Click on the name of the instance where the database you want to alter or delete is located.
Go to the Databases tab: This tab lists all the databases in the selected instance.
Select the database: Click on the name of the database you wish to alter or delete.
Delete the database: If you want to delete the database, click the Delete button. Confirm your decision in the Delete database dialog box by clicking Delete again.
To alter a database;
Connect to the primary instance: You can connect to your Cloud SQL instance using various methods such as Cloud Shell, SQL Server Management Studio (SSMS), or any other SQL client. You'll need the IP address of your instance, the SQL Server port (usually 1433), and the necessary credentials.
Alter or remove the database: Once connected, you can use standard SQL commands to alter or remove a database.
sp_renamedb @olddbname, @newdbname;
CREATE DATABASE @databasename;
DROP DATABASE @databasename;
ALTER DATABASE your_database_name
SET NEW_OPTION = VALUE;
Please note the following:
Thanks for your reply
Database is in synchronous mode and not able to delete
Below is the error message Kindly let me know how to resolve the issue
TITLE: Microsoft SQL Server Management Studio
------------------------------
Drop failed for Database 'dbname'. (Microsoft.SqlServer.Smo)
For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18206.0+((SSMS_Rel).19102...
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
The database 'dbname' is currently joined to an availability group. Before you can drop the database, you need to remove it from the availability group. (Microsoft SQL Server, Error: 3752)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=15.00.4312&Evtsrc=MSSQLServ...
------------------------------
BUTTONS:
OK
Thanks for the clarification. The error message you're seeing indicates that the database you're trying to delete is part of an availability group.
Before you can drop a database that is part of an availability group, you need to remove it from the availability group. Here's how you can do this:
Connect to the primary replica: Using SQL Server Management Studio (SSMS), connect to the primary replica of the availability group.
Remove the database from the availability group: Run the following T-SQL command:
ALTER AVAILABILITY GROUP [Your_Availability_Group_Name]
REMOVE DATABASE [Your_Database_Name];
3. Replace Your_Availability_Group_Name
with the name of your availability group and Your_Database_Name
with the name of the database you want to remove.
4. Drop the database: After successfully removing the database from the availability group, you should be able to drop the database using the DROP DATABASE
command:
DROP DATABASE [Your_Database_Name];
You can delete the database on the primary instance using UI or gcloud tool or Cloud SQL API: