how to find if replication role of Azure SQL database

666 views Asked by At

I am trying to find the replication role of Azure SQL DB (Primary or Secondary).

I used : Get-AzureRmSqlDatabase command but could not find the replication information.

Is there a different powershell command to find replication role ?

2

There are 2 answers

0
juvchan On

The Get-AzureRMSqlDatabaseReplicationLink cmdlet replaces the Get-AzureSqlDatabaseCopy cmdlet.

It gets all geo-replication links between the specified Azure SQL Database and a resource group or AzureSQL Server.

Get-AzureRmSqlDatabaseReplicationLink -DatabaseName <databaseName> -PartnerResourceGroupName <partnerResourceGroupName> -ResourceGroupName <resourceGroupName> -ServerName <databaseServerName> | Select Role

Below is the result of the Azure PowerShell cmdlet above which get the replication role of the geo-replicated Azure SQL Databases.

enter image description here

Note:

The partnerResourceGroupName and resourceGroupName can be the same if the geo-replicated databases and server are in the same resource group as the primary.

0
4c74356b41 On

you need to use the Get-AzureRmSqlDatabaseReplicationLink cmdlet. Refer to this article:
https://learn.microsoft.com/en-us/azure/sql-database/scripts/sql-database-setup-geodr-and-failover-database-powershell

$database = New-AzureRmSqlDatabase  -ResourceGroupName $primaryresourcegroupname `
    -ServerName $primaryservername `
    -DatabaseName $databasename -RequestedServiceObjectiveName "S0"

# Establish Active Geo-Replication
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $primaryresourcegroupname -ServerName $primaryservername
$database | New-AzureRmSqlDatabaseSecondary -PartnerResourceGroupName $secondaryresourcegroupname -PartnerServerName $secondaryservername -AllowConnections "All"

# Initiate a planned failover
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $secondaryresourcegroupname -ServerName $secondaryservername
$database | Set-AzureRmSqlDatabaseSecondary -PartnerResourceGroupName $primaryresourcegroupname -Failover

# Monitor Geo-Replication config and health after failover
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $secondaryresourcegroupname -ServerName $secondaryservername
$database | Get-AzureRmSqlDatabaseReplicationLink -PartnerResourceGroupName $primaryresourcegroupname -PartnerServerName $primaryservername