Skip to content

Sync-DbaAvailabilityGroup intermittently working where secondary is setup for readonly routing #9648

Description

Verified issue does not already exist?

No, I did not search

What error did you receive?

I'm using Sync-DbaAvailabilityGroup to sync all the objects between the Primary and Secondary. This working just fine on all our AlwaysOn Clustered SQL Servers, except where the secondary is configured to be readonly. I have tried this on two AlwaysOn Clustered SQL Servers configured for readonly routing. One set is Pre-Prod (so not as busy as Prod) and the other one is a Production Cluster which is busy most of the time.
The Sync-DbaAvailabilityGroup job works 99.9 times on the PreProd and fails about 85% on the Production servers. Everything I have reserached points to readonly routing issue as this can be hit an miss because of the different connections the sub commands are marking for the objects to sync.

It says the target database is available for readonly connections. See error below:"WARNING: Failed to sync Job syspolicy_purge_history: The following exception occurred while trying to enumerate the collection: "The target database ('xxxx') is in an availability group and is currently accessible for connections when the application intent is set to read only.

So my question is, is this a known issue that Sync-DbaAvailabilityGroup job does not correctly work on AlwaysOn configurations where readonly routing is setup? If so, is there a timeline to fix this? If not, does anyone know how to get around this?

Steps to Reproduce

$AG = Get-DbaAvailabilityGroup -sqlinstance $SqlInstance -AvailabilityGroup $AvailabilityGroup -IsPrimary

if ($AG.IsPrimary -eq $true) {

      #$AvailabilityGroup = 'RRRRRRRRRRRRRRRRRRRRR'   
    # Replicate all dependent local objects to SecondaryReplica
    write-host "Job is running on PrimaryReplica. Syncing all dependent local objects."

    #$SyncResults = Sync-DbaAvailabilityGroup -Primary $SQLInstance -AvailabilityGroup $AvailabilityGroup -DestinationSqlInstance $DestinationSqlInstance
    $SyncResults = Sync-DbaAvailabilityGroup -Primary $SQLInstance -AvailabilityGroup $AvailabilityGroup -Secondary  $Secondary 
    $SyncResults | ft -AutoSize -Wrap
    
    
    Foreach ($SyncResult in $SyncResults) {
        if ($SyncResult.Status -eq 'Failed') {

        $WarningMess = $SyncResult.Type + ' ' + $SyncResult.Name + ' ' + $SyncResult.Notes
        SendAlert
        }
    }

Please confirm that you are running the most recent version of dbatools

I am using version 2.1.30

Script 2.1.30 dbatools {Select-DbaObject, Set-DbatoolsConfig, Add-DbaAgDatabase, Add-DbaAgListener...}

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.7009
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.7009
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU30) (KB5049235) - 15.0.4415.2 (X64) Nov 18 2024 17:45:37 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: )

.NET Framework Version

.NET Framework 4.7.4126.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions