A few days ago, I have a problem with SQL elastic pool in Azure.
I have an application that copies a database that is in a SQL Elastic pool, after a few days in production, started to return the message:
{"code":"40857","message":"Elastic pool not found for server: 'XXX', elastic pool name: 'XXX'."}
I tried to make the copy by the web admin panel without success as well.
Get error log:
"properties": {
"statusMessage": "{\"status\":\"Failed\",\"error\":{\"code\":\"ResourceOperationFailure\",\"message\":\"The resource operation completed with terminal provisioning state 'Failed'.\",\"details\":[{\"code\":\"40857\",\"message\":\"Elastic pool not found for server: 'XXX', elastic pool name: 'XXX'.\"}]}}",
"statusCode": "Accepted",
"serviceRequestId": "XXX"
}
I have checked all the information, and they are correct! It was working and stopped.
Help me please
Let me provide you workarounds since I do not know why it stopped working. Please try using PowerShell as a workaround.
New-AzureRmSqlDatabaseCopy
-ResourceGroupName “source”
-ServerName “source”
-DatabaseName “source”
-CopyResourceGroupName “target”
-CopyServerName “target”
-CopyDatabaseName “target”
-ElasticPoolName “target”
Try specifying the -ElasticPoolName and without that parameter.
If the above does not work, move the database into a standalone performance level then copy it.
Set-AzureRmSqlDatabase -ResourceGroupName $resourcegroupname `
-ServerName $servername `
-DatabaseName $firstdatabasename `
-RequestedServiceObjectiveName "S0"
Related
I'm trying to convert from New-AzureRmSqlDatabaseCopy to New-AzSqlDatabaseCopy, but I'm getting an error when trying to copy a database to the same server:
Microsoft.Rest.Azure.CloudException: Long running operation failed
with status 'Failed'. Additional Info:'The sku 'ElasticPool' specified
is invalid.'
New-AzSqlDatabaseCopy `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $templateDbName `
-CopyDatabaseName $newDbName `
-CopyServerName $serverName `
-CopyResourceGroupName $resourceGroupName
The database copies successfully when using New-AzureRmSqlDatabaseCopy, I can't figure why New-AzSqlDatabaseCopy would be different. I've tried specifying the -ElasticPoolName and -ServiceObjectName parameters, but no luck.
I don't know if this is relevant, but I'm running the PowerShell from an Azure runbook.
Make sure that the new Elastic Pool has the same name and as the old Elastic Pool. Also make sure the SKU are same for both the elastic pools. If the resource groups are in different regions, the SKU (Standard?) for elastic pools may differ causing issues while copying the database.
I'm having a problem with azure in trying to remove a database that exists in a secondary fail over group but doesn't exist in the primary. I've not idea how it got into this state....
If I try to add to the primary....
$failoverGroup = Get-AzSqlDatabase -ResourceGroupName "SASepa" -ServerName "sasepa" -DatabaseName "SEPA-e0e9c319-6237-4c2a-9204-cf9bd53f4a83Test" | Add-AzSqlDatabaseToFailoverGroup -ResourceGroupName "SASepa" -ServerName "sasepa" -FailoverGroupName "sa-sepa-test-fog" -Debug
I get the following error...
{
"error": {
"details": [
{
"code": "45138",
"message": "The destination database name 'SEPA-e0e9c319-6237-4c2a-9204-cf9bd53f4a83Test' already exists on the
server 'sasepa-geo'."
}
],
"code": "FailoverGroupUnableToPerformGroupOperationOnDatabases",
"message": "The operation cannot be performed due to multiple errors."
}
}
If I try to delete from the secondary based on the above error....
$failoverGroup = Get-AzSqlDatabase -ResourceGroupName "SASepa" -ServerName "sasepa-geo" -DatabaseName "SEPA-e0e9c319-6237-4c2a-9204-cf9bd53f4a83Test" | Remove-AzSqlDatabaseFromFailoverGroup -ResourceGroupName "SASepa" -ServerName "sasepa-geo" -FailoverGroupName "sa-sepa-test-fog" -Debug
I get the following error...
{
"error": {
"code": "FailoverGroupUpdateOrDeleteRequestOnSecondary",
"message": "Modifications to the failover group are not allowed on a secondary server. Execute the request on the
primary server."
}
}
If I try to modify the primary group by removing the database with the following command...
$failoverGroup = Get-AzSqlDatabase -ResourceGroupName "SASepa" -ServerName "sasepa" -DatabaseName "SEPA-e0e9c319-6237-4c2a-9204-cf9bd53f4a83Test" | Remove-AzSqlDatabaseFromFailoverGroup -ResourceGroupName "SASepa" -ServerName "sasepa" -FailoverGroupName "sa-sepa-test-fog" -Debug
I get the following error...
WARNING: Database to be removed with id
/subscriptions/4c193689-f235-4d0d-9aa9-006459abc199/resourceGroups/SASepa/providers/Microsoft.Sql/servers/sasepa/databa
ses/SEPA-e0e9c319-6237-4c2a-9204-cf9bd53f4a83Test in Failover Group with name: 'sa-sepa-test-fog' in server 'sasepa
does not exist'.
So I'm stuck in a loop
I can't add to the primary as it says it already exists on the secondary
I can't remove from the secondary as it says I need to perform modifications on the primary
I can't remove from the primary as it doesn't exist
How can I resolve this?
Thanks,
I create a failover group and add two databases(Mydatabase and DB1) to in it. I tried delete DB1 in primary server On Portal. Then database in the secondary fail will auto be deleted later.
For example, when delete a database in primary server, see the warning:
Then I run the Powershell command remove the DB1 and get the same error with you.
I just wait a moment and refresh the failover group, the DB1 not exist now.
So I'm a little confused that why you say that the database exists in a secondary fail over group but doesn't exist in the primary. I think the most possible reason is caused by the cache.
You could refresh the failover group and check again.
Hope this helps.
I am creating a simple Azure logic app that uses a function to:
Delete a slave database
Restore a copy of a master database (with the same name as the removed slave)
Remove Database
# Remove slave database
Remove-AzSqlDatabase `
-DatabaseName $RestoreDatabaseName `
-ServerName $ServerName `
-ResourceGroupName $ResourceGroupName
Write-Host "Removed slave database"
Restore PIT Backup of Master
# Restore database
Restore-AzSqlDatabase `
-FromPointInTimeBackup `
-PointInTime (Get-Date).AddMinutes(-2) `
-ResourceGroupName $ResourceGroupName `
-ServerName $ServerName `
-TargetDatabaseName $RestoreDatabaseName `
-ResourceId $Database.ResourceID `
-ElasticPoolName $ElasticPoolName
The issue i am having is that after removing the database, Azure still sees the database on the server and so i get the following error when restoring:
The destination database name 'Slave' already exists on the server
'server address'.
I cant find any way to check if this has been fully removed before starting the next function. Any help on how to achieve this would be greatly appreciated.
You can use Get-AzSqlDatabase to check if the DB is still in play.
Get-AzSqlDatabase -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database02"
Placing this in a loop with a sleep will give you a poll to check when the DB is finally gone for good and you can then resume your processing.
Start-Sleep -s 15
Make sure you have a circuit breaker in your logic to prevent and endless loop in the case of a failed deletion.
It may be easier to restore your DB with a new name to avoid the delay e.g. MyDb<yyyymmdd>
Or alternatively, use the Azure REST API from SQL DB delete.
DELETE https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb?api-version=2017-10-01-preview
and monitor the location response of the 204 Accepted to determine when the database has been completely removed. Azure Durable Functions give you a great monitor pattern you can use.
I'm trying to clone an existing Azure SQL DB that's in an elastic pool to a standard SQL server in a different resource group. Whenever I run (with Az Powershell)
Restore-AzSqlDatabase -FromPointInTimeBackup -PointInTime (Get-Date) -ResourceGroupName $TargetRGName -ServerName $TargetServerName -TargetDatabaseName $TargetDBName -ResourceId $Database.ResourceID,
I get the error Long running operation failed with status 'Failed'. Additional Info:'An unexpected error occured while processing the request.
According to my script, you use Point-in-time restoration to restore your database. But we can not use the way to restore a database on the different servers. For more details, please refer to https://learn.microsoft.com/en-us/azure/sql-database/sql-database-recovery-using-backups#point-in-time-restore.
So if you want to restore the database on the different server, I suggest you use geo-store. If we use it, we can restore a SQL database on any server in any Azure region from the most recent geo-replicated backups. For further information, you read the official document. Regarding how to implement it by powershell, please refer to the following script
Connect-AzAccount
# get geo backup
$GeoBackup = Get-AzSqlDatabaseGeoBackup -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database01"
#restore database
Restore-AzSqlDatabase -FromGeoBackup -ResourceGroupName "TargetResourceGroup" -ServerName "TargetServer" -TargetDatabaseName "RestoredDatabase" -ResourceId $GeoBackup.ResourceID -Edition "Standard" -RequestedServiceObjectiveName "S2"
I'm trying to clone an Azure SQL Database using the PSCmdlet New-AzSqlDatabaseCopy (after being told that Restore-AzSqlDatabase won't let me do cross-server copies). My command is as follows:
New-AzSqlDatabaseCopy -ServerName $SourceDatabase.ServerName `
-ResourceGroupName $SourceDatabase.ResourceGroupName `
-DatabaseName $SourceDatabase.DatabaseName `
-ServiceObjectiveName $SourceDatabase.CurrentServiceObjectiveName `
-CopyServerName $TargetServerName `
-CopyResourceGroupName $TargetResourceGroupName `
-CopyDatabaseName $TargetDBName `
-ElasticPoolName $ElasticPoolName`
-ErrorAction stop
The source database is in a different server and resource group than the target, and in a different elastic pool than the target will be.
I've checked and double-checked all of my parameters to make sure they are correct, and I ran it with -whatif and everything looks good (except the creation date is 1/1/0001 but i'm not super concerned about that yet)
However, when I run the command, I get New-AzSqlDatabaseCopy : Long running operation failed with status 'Failed'. Additional Info:'The sku 'ElasticPool' specified is invalid.' Any input would be appreciated
Make sure that the new Elastic Pool has the same name and as the old Elastic Pool. Also make sure the sku are same for both the elastic pools. If the resource groups are in different regions, the sku for elastic pools may differ causing issues while copying the database.
SQL server - sql_server_A
--- Elastic Pool - elastic_pool_1
----- database - template_db
SQL server - sql_server_B
--- Elastic Pool - elastic_pool_1 (name equal to Elastic Pool from sql_server_A)
References:
https://github.com/Azure/azure-libraries-for-net/issues/41
https://learn.microsoft.com/en-us/azure/sql-database/scripts/sql-database-move-database-between-pools-powershell
https://learn.microsoft.com/en-us/rest/api/sql/databases/createorupdate
https://learn.microsoft.com/en-us/rest/api/sql/elasticpools/createorupdate
Remove the "-ServiceObjectiveName" parameter. Only -elasticpool OR -ServiceObjectiveName can be used.