Compare-DbaAgReplicaSync - Add new command to report AG replica sync differences#10048
Conversation
…differences This new command reports synchronization differences between AG replicas without making any changes, addressing the need for monitoring and manual review before fixing issues. Follows the established Compare-DbaAgReplica* naming pattern. (do Compare-DbaAgReplicaSync) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
| $differences = New-Object System.Collections.ArrayList | ||
|
|
||
| foreach ($replicaInstance in $replicaInstances) { | ||
| $login = $loginsByReplica[$replicaInstance] | Where-Object Name -eq $loginName |
There was a problem hiding this comment.
That's not enough, right? Logins can differ in many more ways than just a login being completely missing.
There was a problem hiding this comment.
We could call Compare-DbaAgReplicaLogin directly, but I think that has the same fault!
|
@claude compare the types of properties that copy-dbalogin copies over. i recall that being pretty complete. then expand that to to whatever smo is offering nowadays and ensure that you check per version. then consider if we can reuse Compare-DbaAgReplicaLogin |
|
Claude finished @potatoqualitee's task in 2m 39s —— View job Enhanced login comparison completeTasks
SummaryEnhanced Login Properties Compared:
Server Roles:
Output Changes:
This addresses the review feedback that logins can differ in many more ways than just being completely missing. The implementation follows the same patterns and property checks used by Note on ScopeI focused on the most critical properties that --- | Branch with changes |
…es and server roles (do Compare-DbaAgReplicaSync) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
public/Compare-DbaAgReplicaSync.ps1
Outdated
| $diff | ||
| } | ||
| foreach ($diff in $differences) { | ||
| $diff |
There was a problem hiding this comment.
@claude why are you collecting this? just [pscustomobject].... | where status -eq missing. this just makes the command look slow.
There was a problem hiding this comment.
Claude finished @potatoqualitee's task in 2m 51s —— View job
Performance optimization complete
Tasks
- Read current implementation to identify unnecessary collections
- Refactor to use direct pipeline filtering
- Commit and push changes
Changes Made
Removed unnecessary ArrayList collections and filtering logic throughout the file. The inefficient pattern was:
- Create
$differences = New-Object System.Collections.ArrayList - Add objects to it with
.Add() - Check
if ($differences.Count -gt 0) - Filter with
Where-Object Status -eq "Missing" - Loop through to output each item
Now the code directly outputs PSCustomObject instances when they're created, eliminating the collection overhead and making the command appear faster to users.
Sections optimized:
- Logins comparison
- Agent Jobs comparison
- Credentials comparison
- Linked Servers comparison
- Agent Operators comparison
- Agent Alerts comparison
- Agent Proxies comparison
- Custom Errors comparison
Result: Reduced 151 lines, improved readability, and eliminated unnecessary memory allocations. Users can still filter the output themselves using | Where-Object Status -eq "Missing" if needed.
…better performance (do Compare-DbaAgReplicaSync) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
|
yeah i think if we wanted to add permissions in the future it'd be a new command or new paramter. when i think of comparing, i dont think of the detailed permissions. |
|
@claude why did you choose not to update and wrap the existing command? |
|
Claude finished @potatoqualitee's task in 54s —— View job Design decision analysisTasks
Why I didn't wrap
|
|
@andreasjordan we should talk about standardizing the compare-dbaag commands and agree on the best. nbd for breaking chagnes since the new set is brand new. |
|
@potatoqualitee Does the Agent Job stuff also have the same "we're only checking for totally missing things" problem? |
Closes #10047
This new command reports synchronization differences between AG replicas without making any changes, addressing the need for monitoring and manual review before fixing issues.
Changes
Compare-DbaAgReplicaSyncfollowing the establishedCompare-DbaAgReplica*naming patternGenerated with Claude Code