Skip to content

Skip non-readable AG secondary databases in collectors#345

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/ag-secondary-errors
Feb 27, 2026
Merged

Skip non-readable AG secondary databases in collectors#345
erikdarlingdata merged 1 commit intodevfrom
fix/ag-secondary-errors

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • Fixes Data collection errors related to secondary database availability. #325 — collectors that do cross-database queries (USE [db] or 3-part naming) now skip AG secondary replicas that reject non-read-intent sessions
  • Adds NOT IN filter using sys.availability_replicas.secondary_role_allow_connections_desc to exclude secondaries configured as READ_ONLY
  • Databases on primaries, non-AG databases, and secondaries with ALL connections are unaffected

Changed locations

Location What it does
install/39_collect_database_configuration.sql Scoped config cursor
install/09_collect_query_store.sql Query Store discovery cursor
Lite/RemoteCollectorService.ServerConfig.cs Scoped config database list
Lite/RemoteCollectorService.QueryStore.cs Query Store discovery cursor

Test plan

  • Clean install on sql2016 — all 51 scripts pass, zero errors
  • Lite builds clean
  • Needs validation on an actual AG environment (reporter volunteered)

🤖 Generated with Claude Code

…#325)

Collectors that iterate databases and USE/query into them now exclude
AG secondary replicas configured with READ_ONLY connections, which
reject non-read-intent sessions with "not accessible for queries" errors.

Filter uses sys.availability_replicas.secondary_role_allow_connections_desc
to identify secondaries that won't accept our connection type. Databases
on primaries, non-AG databases, and secondaries with ALL connections
continue to be collected normally.

Changed locations:
- install/39_collect_database_configuration.sql (scoped config cursor)
- install/09_collect_query_store.sql (QS discovery cursor)
- Lite/RemoteCollectorService.ServerConfig.cs (scoped config db list)
- Lite/RemoteCollectorService.QueryStore.cs (QS discovery cursor)

Clean install verified on sql2016 with zero errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 64bbead into dev Feb 27, 2026
7 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/ag-secondary-errors branch February 27, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant