diff --git a/.github/workflows/darling-upgrade-shapes.yml b/.github/workflows/darling-upgrade-shapes.yml index 3c0fbb930c..a341b849a7 100644 --- a/.github/workflows/darling-upgrade-shapes.yml +++ b/.github/workflows/darling-upgrade-shapes.yml @@ -24,7 +24,7 @@ permissions: # The released builds the legs install first. Change them here and nowhere else. env: - DARLING_CURRENT_RELEASE: '3.10.0' + DARLING_CURRENT_RELEASE: '3.11.0' DARLING_OLD_RELEASE: '3.7.1' concurrency: diff --git a/CHANGELOG.md b/CHANGELOG.md index 802ec75468..4df579059f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,210 @@ Releases before 3.0.0 are not archived: those entries carry no prose to move. ## [Unreleased] +## [3.12.0] - 2026-10-30 + +Full entries: [docs/changelog/3.12.md](docs/changelog/3.12.md) + +### Important + +- **Upgrading from 3.11 runs the Darling store migrations V215 through V229 on the service's first start** +- **The Client Timeouts alert is on after the upgrade, in Darling and Lite** ([#5736]) +- **Lite's DuckDB schema stays at version 78** +- **Self-managed stores: re-run `provision-roles.sql` after upgrading** ([#6542], [#6395], [#6386], [#6389], [#6392], [#6393], [#6394], [#6396], [#6397], [#6398], [#6400], [#6401], [#6454], [#6455], [#6569], [#6928], [#6743]) +- **New msdb grants for existing monitoring logins** ([#6874], [#6873]) +- **The Darling web dashboard and MCP server, and Lite's MCP server, need a token once turned on** ([#6507], [#6557]) +- **Web dashboard Admin writes stay off after an upgrade until `web.allowAdminWrites` is true** ([#6600], [#6745]) +- **Adding servers is stricter** ([#6583], [#6752]) + +### Added + +- **Notification routes can match on alert severity** ([#6928]) +- **Blocking colours follow settable blocking bands** ([#6927]) +- **Alert threshold overrides can be set for a server tag** ([#6926]) +- **The Darling grant script has an Amazon RDS form** ([#6889]) +- **Darling warns before an identity column runs out of values** ([#6875]) +- **Darling checks the SQL Server Agent alert setup** ([#6874], [#6894], [#6908]) +- **Darling watches backups and CHECKDB per database** ([#6873], [#6902], [#6946]) +- **Darling reads PostgreSQL server logs written in a named local log_timezone** ([#6866]) +- **A Darling docs page lists every MCP tool and the store tables it reads** ([#6853]) +- **Darling can front several stores with one web address and one MCP endpoint** ([#6840], [#6917]) +- **The Darling viewer's Collector Schedules window has a Find box and a Disabled only filter.** ([#6768]) +- **`get_job_history` takes a `min_duration_seconds` filter, and I/O anomaly briefs name it.** ([#6614]) +- **A signed-in web dashboard admin can make Admin writes on the managed store, once `web.allowAdminWrites` is on** ([#6600], [#6745]) +- **Darling now collects Query Store hints, lists them with `get_query_store_hints`, and Change Watch sees one set or cleared.** ([#6581]) +- **Agents can recompile a module and create or drop a plan guide through Level 3 server actions, with Undo.** ([#6569]) +- **A request's brief names the earlier report with the same root cause** ([#6565]) +- **Client Timeouts alerts name the client host and carry a client_timeouts evidence section** ([#6553]) +- **Darling MCP supports named tokens with roles, and an operator token can set a notification route's agent settings** ([#6542], [#6395]) +- **The Darling install scripts work with the MSI package and refuse a machine that the MSI owns** ([#6480]) +- **The Darling installer offers to add you to the operator group** ([#6478]) +- **Darling prints the monitoring login and grant script, and the connection test names missing grants** ([#6472]) +- **The Darling zip ships Install-Darling.cmd, and the installer offers to restart elevated** ([#6469]) +- **A Darling page on how to back up, restore and move the store** ([#6411]) +- **Darling MCP write tools return the previous value and an undo call** ([#6403]) +- **Darling MCP get_server_settings reads what edit_server changes** ([#6402]) +- **Darling MCP can switch agent actions off and undo a non-plan agent change.** ([#6401]) +- **Darling MCP can write, approve and reject agent notes, close an investigation request, and handle practice requests and report feedback.** ([#6400]) +- **Darling MCP has a purge_expired_mute_rules write tool** ([#6399]) +- **Darling MCP can add, edit and delete known patterns.** ([#6398]) +- **Darling MCP can read and set database state expectations** ([#6397]) +- **Darling MCP can set a collector's database scope and reset a scope's schedules** ([#6396]) +- **Darling MCP can make and remove webhook signing keys, for the default webhook and for each route.** ([#6394]) +- **Darling MCP can set the service flags** ([#6393]) +- **Darling MCP can set the default notification channels** ([#6392]) +- **The Darling viewer shows Fleet Sweeps, alert rules and Custom Views** ([#6390]) +- **The web dashboard Recommendations tab has Generate now and Ask AI** ([#6389]) +- **The Darling viewer shows Resource Semaphore, Plan Cache by Type, Sessions by Application and more panels that the web dashboard already had** ([#6388]) +- **The Darling viewer shows PostgreSQL configuration changes, the logging audit and deadlock graphs** ([#6387]) +- **The web dashboard Active Queries panel can read the running requests live** ([#6386]) +- **The Darling viewer charts the four PostgreSQL trends** ([#6385]) +- **The Darling viewer shows Sweep Pressure and Heaviest Collectors panels** ([#6384]) + +### Changed + +- **Recommendations say "times its usual variation" instead of "robust σ"** ([#6925]) +- **Updated to .NET SDK 10.0.403, DuckDB.NET 1.5.6.1 and newer AWSSDK and ProtectedData packages** ([#6915]) +- **Client Timeouts leaves out the VS Code mssql extension's metadata cancels** ([#6856], [#6858]) +- **get_forced_plans and get_query_store_hints read each first-seen time in one pass** ([#6833], [#6876]) +- **The 31-day daily summary keeps closed days until the next UTC day plus 2 hours** ([#6809]) +- **get_query_store_clutter and the Darling viewer's Query Store clutter view are faster on large servers** ([#6808]) +- **Darling viewer Top Queries by Duration looks up modules only for the ranked statements.** ([#6804]) +- **FinOps High Impact and Optimization are faster, with no temp spill.** ([#6803]) +- **The Darling fleet `get_resource_use_by_tag` read is much faster: it reads narrow hourly and daily tables and is served from the read cache** ([#6800], [#6794], [#6865], [#6945]) +- **Darling's Job History page reads its per-job statistics from a new index** ([#6798]) +- **`--backfill-rollups` and `--recompress` can take the store's free space, and the data volume is measured on Linux.** ([#6791]) +- **Query Store regressions list a query for cost only when it added at least 1 second of CPU** ([#6781]) +- **A re-fire of an alert now joins a request that is already reported, so it opens no new request.** ([#6778]) +- **The Darling viewer and Lite Running Jobs tabs now show a short note when the collector has not run.** ([#6764]) +- **Four MCP empty answers now say what kind of nothing they are.** ([#6757]) +- **Web server add and edit now refuse Windows sign-in over an unverified certificate unless the operator allows it, as MCP does.** ([#6752]) +- **`analyze_server` now ranks a long blocking chain by how long it waited and says when it is still open.** ([#6746]) +- **Self-managed store upgrades now say to re-run provision-roles.sql, the two CLI verbs accept the same `--auth` words, and a per-server collector retention is refused.** ([#6743]) +- **`submit_investigation_report` now tells an agent that `family_of` needs the full request id.** ([#6729]) +- **The Darling upgrade script now prints a post-upgrade checklist that an operator can work.** ([#6724]) +- **Five MCP tool descriptions are fixed where agents guessed wrong** ([#6713]) +- **The Darling viewer and Lite match the web dashboard on dropped databases, labels, job history, wording and strip gaps** ([#6651]) +- **The health parser says how many events were read when it finds none that qualify** ([#6650]) +- **The hourly Darling aggregate compression check reads sizes only for aggregates that have no policy** ([#6648]) +- **get_store_log gives the TimescaleDB poor compression ratio warning its own class** ([#6647]) +- **The PARAMETER_SENSITIVITY and QUERY_SPILLS findings now name the queries behind them.** ([#6640]) +- **Store migration V215 adds six indexes on the Darling investigation tables** ([#6637]) +- **The investigation resolve check is about 5 times faster in Darling and Lite.** ([#6633]) +- **The Blocking Incidents chart says why it is empty when lock waits exist** ([#6622]) +- **Darling opens no investigation request for a story that recurs at this hour** ([#6596]) +- **Darling and Lite MCP tool descriptions are reworded where investigation agents went wrong** ([#6589]) +- **A SQL Server port is refused on new entries and warned about on existing ones** ([#6583]) +- **get_forced_plans pages its list and filters by query_id and plan_id** ([#6560]) +- **The Darling web dashboard and MCP server, and Lite's MCP server, need a token once turned on** ([#6507], [#6557]) +- **The Darling command line tests Windows authentication servers as the service** ([#6476]) +- **--enable-web and --enable-mcp print the address and the next step** ([#6474]) +- **The Darling viewer finds darling.json through the installed service** ([#6473]) +- **The Darling Windows zip no longer needs a separate .NET runtime** ([#6471]) +- **The Darling installer waits until the service is ready and then prints the next steps** ([#6470]) +- **Darling starts with no monitored servers, and a first install needs no hand-edited darling.json** ([#6468]) +- **Darling says a Query Store replica has no effect on Azure SQL Database** ([#6459]) +- **The troubleshooting page is a symptom table for Lite and Darling** ([#6422]) +- **The Lite README is a short front door, and the Lite guide puts install and configuration first** ([#6419]) +- **The Darling install docs now tell one story** ([#6417], [#6418], [#6409], [#6410], [#6429], [#6430]) +- **The Darling documentation is reorganized into task pages with an index** ([#6416], [#6420]) +- **New Darling pages for day-to-day admin tasks and for every service command line verb** ([#6412], [#6413]) +- **The Client Timeouts alert is on by default in Darling and Lite** ([#5736]) +- **The Query Store regressions read and `get_collection_health` are much faster on large Darling stores, and the regressions read no longer misses cost regressions on long windows** ([#5506], [#6750]) + +### Fixed + +- **The Darling web dashboard keeps the page on screen while it auto-refreshes** ([#6933]) +- **Blocking chains in analysis no longer link unrelated sessions that reused a session number** ([#6931]) +- **The Darling web Overview strips draw at full size, and the Daily Health Calendar fills its card** ([#6929]) +- **Saving an edit to an existing notification route from the Darling web page works again** ([#6928]) +- **The Darling upgrade script runs under PowerShell 7** ([#6920]) +- **Unregistered external alerts from different sources or labels stay in separate investigation requests** ([#6919]) +- **Idle servers answer empty, not unavailable, for query_stats and procedure_stats reads** ([#6903]) +- **The new Agent Alerts, Database Protection and Identity Capacity views read cleanly** ([#6901], [#6906], [#6907]) +- **Azure SQL Managed Instance system_health events are collected again** ([#6897]) +- **The blocking snapshot no longer names its own session as the blocker** ([#6896]) +- **Extended Events captures that cannot run are no longer counted as healthy or as down** ([#6893], [#6912]) +- **Darling no longer writes its own ERROR lines into a monitored PostgreSQL server's log** ([#6888]) +- **Azure SQL Managed Instance now reads SQL Agent as running** ([#6886]) +- **The Darling viewer fleet card shows the whole Collectors line, and query tag text uses words** ([#6878]) +- **Deadlocks and blocked process reports are collected again on Azure SQL Managed Instance** ([#6868]) +- **The tempdb tab explains why it is empty in Lite and the Darling viewer** ([#6861], [#6869]) +- **get_job_history and get_resource_use_by_tag answer with the display name, not the connection key** ([#6860]) +- **Lite logs a permission-denied collector run as one Warning** ([#6859]) +- **A missing Resource Use By Tag source is named in the same words in Lite, the Darling viewer and the MCP tool** ([#6850]) +- **PostgreSQL 10 to 13 targets store statement stats and wait samples correctly** ([#6836], [#6849]) +- **The slow-read log records the server when the server id is negative** ([#6834]) +- **Charts keep a plot at least 100 pixels tall at 1366x768, and axis titles stay clear of tick labels** ([#6832]) +- **Four Darling web pages use the page's own words instead of MCP text** ([#6831]) +- **get_finops refuses an unsupported hours_back for the utilization and index_analysis views in the view's own words** ([#6830]) +- **get_query_store_regressions explains a baseline or replay window that is older than the kept data** ([#6829], [#6877]) +- **Collector counts agree on every Darling surface, and a refused collector names the grant** ([#6828], [#6932]) +- **Health-parser reads check for a truncated ring buffer over their own window** ([#6827]) +- **Save is visible in the Darling viewer's Add and Edit server dialog at its default width** ([#6823]) +- **The Darling upgrade script takes a new rollback backup when the last upgrade finished** ([#6821]) +- **Darling Query Store panels over a window older than 3 days are no longer refused by the row guard** ([#6807]) +- **The slow-read log now keeps a read's slowest statements, and records a web read that the browser cancelled.** ([#6795]) +- **Darling web pages cancel their reads when you leave the page** ([#6793]) +- **The Overview tooltip's baseline arrow now shows only for the first series of a chart row.** ([#6787]) +- **The Wait Drill-Down banner is now readable on the Light and Cool Breeze themes.** ([#6773]) +- **A server's own Capture execution plans setting now takes effect.** ([#6771]) +- **The Darling viewer logs a failed schedule read once, not once per waiting caller.** ([#6766]) +- **Investigation blocking evidence no longer counts parallel self-waits, keeps the head blocker's facts, and honors the high-memory signal.** ([#6761]) +- **Darling web: an empty Add route or Write note says what is missing without a request, and Running Jobs and Recommendations text reads plainly.** ([#6760]) +- **Four Darling web pages no longer say two things at once.** ([#6759]) +- **Darling viewer fixes to the grant script account, PostgreSQL notes and sidebar buttons.** ([#6758]) +- **Three web layout fixes in the Darling dashboard.** ([#6756]) +- **Lite keeps its first-run server step until the servers are bound to their settings.** ([#6755]) +- **Query Store reads now give the right status word on a Secondary role, with Query Store off, and for an empty forced-plan window.** ([#6749]) +- **Stopping the Darling service during a pass no longer logs a false alert-pass warning.** ([#6748]) +- **The viewer now shows fleet-wide times in a fleet-wide zone, and each server tab's times in that server's own zone.** ([#6747]) +- **The generated grant script and the permissions doc now loop databases with a cursor, not `sp_MSforeachdb`.** ([#6741]) +- **Journal rows for refused agent actions, plan undo and operator route changes now record the right caller.** ([#6740], [#6751]) +- **An investigation claim's later calls are now tied to the named token that made the claim.** ([#6738]) +- **Plan guide drop answers now follow `mcp.dataDetail`, and forcing or unforcing a Query Store plan honors the excluded database list.** ([#6737]) +- **Choosing the web dashboard option in the Darling MSI now makes a web token, so the dashboard starts.** ([#6736]) +- **A server action switch no longer turns on for an Azure SQL target whose tool always refuses the action.** ([#6727]) +- **A generic webhook can now close an alert, and a PagerDuty resolve now closes the incident the trigger opened.** ([#6718], [#6723]) +- **Darling now copies the generic webhook, PagerDuty and send-resolutions settings from darling.json on its first start.** ([#6715]) +- **Darling on plain PostgreSQL: the blocking and deadlock baselines stop at the purge horizon** ([#6706]) +- **Alert texts use the right word for a count of one** ([#6700], [#6703]) +- **ANOMALY_WRITE_LATENCY is scored against a write latency baseline** ([#6696]) +- **Chart text keeps its size at high Windows display scaling** ([#6678]) +- **Darling's Query Store reads no longer list the monitor's own statement or statements from dropped databases** ([#6654], [#6659]) +- **Index Analysis no longer shows two banners that contradict each other, and two Settings and plan card labels are corrected** ([#6653]) +- **The Darling viewer charts and grids stay readable on a 1366x768 screen** ([#6652]) +- **Web dashboard pages say MCP field names and raw collector counts in plain words** ([#6649]) +- **The right-sized verdict sentence says what decided the verdict** ([#6646]) +- **A parallel query that waits on itself is no longer counted as blocking** ([#6645], [#6690]) +- **A store that the operator brings now works for every MCP tool and web page that takes a server name** ([#6630]) +- **Darling logs a usable web dashboard and MCP address when it listens on a specific IPv6 address** ([#6609]) +- **Darling Query Store query history now reports a plan whose force was removed as REMOVED.** ([#6598]) +- **The Darling install script registers the service path in quotes** ([#6597]) +- **An agent that holds the live lease gets its claim_id back when it claims again** ([#6576]) +- **Change Watch no longer counts log_reuse_wait_desc as a database configuration change** ([#6566]) +- **get_change_watches accepts state=all, sends each fact once, and can read one watch by watch_id** ([#6561], [#6591]) +- **A Darling Change Watch no longer calls a plan mix shift a regression** ([#6555]) +- **Query Store reads on a readable secondary say it is not collected, and why** ([#6554]) +- **The Client Timeouts alert leaves out SSMS IntelliSense's own cancels** ([#6552]) +- **Change Watch requests get their own family, skip replicated plan changes, and name the database** ([#6551]) +- **Change Watch says whether a plan was forced by automatic plan correction** ([#6550]) +- **SQL Server's own cleanup statements are left out of regression targets, findings and Query Store reads** ([#6548]) +- **The brief keeps the request's only alert when its text is long** ([#6547]) +- **Darling table tuning waits at most 5 seconds for a lock** ([#6539]) +- **Darling investigation requests from analysis findings get the resources and jobs families, not other** ([#6536]) +- **Lite asks again before it uses a saved password for a changed server** ([#6504], [#6559]) +- **Lite clears the Blocking and Deadlocks strips when the window has no events** ([#6482]) +- **The Darling installer tells the truth when it stops, catches an unedited sample, and puts shortcuts where every user sees them** ([#6475]) +- **The investigation brief lists the arguments that submit_investigation_report really takes** ([#6462], [#6546]) +- **Darling builds all three large start-path indexes during the first start of an empty store** ([#6460]) +- **Lite no longer logs a notification_routes warning on its first start** ([#6458]) +- **Fleet-wide windows in the Darling viewer show times one way, and Azure SQL Database notes lead with what the engine lacks** ([#6457]) +- **Darling investigation event webhook posts now send the default User-Agent** ([#6456]) +- **Darling MCP write tools give honest statuses and clearer errors** ([#6455]) +- **Darling server admin tools are current at once and clean up after remove_server** ([#6454]) +- **Reads with nothing stored say empty when the collector ran clean** ([#6453]) +- **The system_health collector keeps reading new events when the ring buffer is full** ([#6441], [#6544], [#6564]) + ## [3.11.0] - 2026-10-22 Full entries: [docs/changelog/3.11.md](docs/changelog/3.11.md) @@ -5838,7 +6042,40 @@ Full entries: [docs/changelog/3.0.md](docs/changelog/3.0.md) [#6381]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6381 [#6382]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6382 [#6383]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6383 +[#6384]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6384 +[#6385]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6385 +[#6386]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6386 +[#6387]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6387 +[#6388]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6388 +[#6389]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6389 +[#6390]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6390 +[#6392]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6392 +[#6393]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6393 +[#6394]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6394 +[#6395]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6395 +[#6396]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6396 +[#6397]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6397 +[#6398]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6398 +[#6399]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6399 +[#6400]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6400 +[#6401]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6401 +[#6402]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6402 +[#6403]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6403 +[#6409]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6409 +[#6410]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6410 +[#6411]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6411 +[#6412]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6412 +[#6413]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6413 +[#6416]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6416 +[#6417]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6417 +[#6418]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6418 +[#6419]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6419 +[#6420]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6420 +[#6422]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6422 +[#6429]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6429 +[#6430]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6430 [#6438]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6438 +[#6441]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6441 [#6447]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6447 [#6443]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6443 [#6450]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6450 @@ -5847,3 +6084,185 @@ Full entries: [docs/changelog/3.0.md](docs/changelog/3.0.md) [#6452]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6452 [#6391]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6391 [#6449]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6449 +[#6453]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6453 +[#6454]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6454 +[#6455]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6455 +[#6456]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6456 +[#6457]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6457 +[#6458]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6458 +[#6459]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6459 +[#6460]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6460 +[#6462]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6462 +[#6468]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6468 +[#6469]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6469 +[#6470]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6470 +[#6471]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6471 +[#6472]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6472 +[#6473]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6473 +[#6474]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6474 +[#6475]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6475 +[#6476]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6476 +[#6478]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6478 +[#6480]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6480 +[#6482]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6482 +[#6504]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6504 +[#6507]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6507 +[#6536]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6536 +[#6539]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6539 +[#6542]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6542 +[#6544]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6544 +[#6546]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6546 +[#6547]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6547 +[#6548]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6548 +[#6550]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6550 +[#6551]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6551 +[#6552]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6552 +[#6553]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6553 +[#6554]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6554 +[#6555]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6555 +[#6557]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6557 +[#6559]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6559 +[#6560]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6560 +[#6561]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6561 +[#6564]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6564 +[#6565]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6565 +[#6566]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6566 +[#6569]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6569 +[#6576]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6576 +[#6581]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6581 +[#6583]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6583 +[#6589]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6589 +[#6591]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6591 +[#6596]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6596 +[#6597]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6597 +[#6598]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6598 +[#6600]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6600 +[#6609]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6609 +[#6614]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6614 +[#6622]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6622 +[#6630]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6630 +[#6633]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6633 +[#6637]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6637 +[#6640]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6640 +[#6645]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6645 +[#6646]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6646 +[#6647]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6647 +[#6648]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6648 +[#6649]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6649 +[#6650]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6650 +[#6651]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6651 +[#6652]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6652 +[#6653]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6653 +[#6654]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6654 +[#6659]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6659 +[#6678]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6678 +[#6690]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6690 +[#6696]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6696 +[#6700]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6700 +[#6703]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6703 +[#6706]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6706 +[#6713]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6713 +[#6715]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6715 +[#6718]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6718 +[#6723]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6723 +[#6724]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6724 +[#6727]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6727 +[#6729]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6729 +[#6736]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6736 +[#6737]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6737 +[#6738]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6738 +[#6740]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6740 +[#6741]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6741 +[#6743]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6743 +[#6745]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6745 +[#6746]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6746 +[#6747]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6747 +[#6748]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6748 +[#6749]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6749 +[#6750]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6750 +[#6751]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6751 +[#6752]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6752 +[#6755]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6755 +[#6756]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6756 +[#6757]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6757 +[#6758]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6758 +[#6759]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6759 +[#6760]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6760 +[#6761]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6761 +[#6764]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6764 +[#6766]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6766 +[#6768]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6768 +[#6771]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6771 +[#6773]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6773 +[#6778]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6778 +[#6781]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6781 +[#6787]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6787 +[#6791]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6791 +[#6793]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6793 +[#6794]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6794 +[#6795]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6795 +[#6798]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6798 +[#6800]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6800 +[#6803]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6803 +[#6804]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6804 +[#6807]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6807 +[#6808]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6808 +[#6809]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6809 +[#6821]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6821 +[#6823]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6823 +[#6827]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6827 +[#6828]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6828 +[#6829]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6829 +[#6830]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6830 +[#6831]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6831 +[#6832]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6832 +[#6833]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6833 +[#6834]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6834 +[#6836]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6836 +[#6840]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6840 +[#6849]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6849 +[#6850]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6850 +[#6853]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6853 +[#6856]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6856 +[#6858]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6858 +[#6859]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6859 +[#6860]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6860 +[#6861]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6861 +[#6865]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6865 +[#6866]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6866 +[#6868]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6868 +[#6869]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6869 +[#6873]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6873 +[#6874]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6874 +[#6875]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6875 +[#6876]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6876 +[#6877]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6877 +[#6878]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6878 +[#6886]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6886 +[#6888]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6888 +[#6889]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6889 +[#6893]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6893 +[#6894]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6894 +[#6896]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6896 +[#6897]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6897 +[#6901]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6901 +[#6902]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6902 +[#6903]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6903 +[#6906]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6906 +[#6907]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6907 +[#6908]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6908 +[#6912]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6912 +[#6915]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6915 +[#6917]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6917 +[#6919]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6919 +[#6920]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6920 +[#6925]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6925 +[#6926]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6926 +[#6927]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6927 +[#6928]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6928 +[#6929]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6929 +[#6931]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6931 +[#6932]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6932 +[#6933]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6933 +[#6945]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6945 +[#6946]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6946 diff --git a/Darling/Darling.Tests/Fixtures/migration-ladder-v3.11.0.sql b/Darling/Darling.Tests/Fixtures/migration-ladder-v3.11.0.sql new file mode 100644 index 0000000000..a5f25ec878 --- /dev/null +++ b/Darling/Darling.Tests/Fixtures/migration-ladder-v3.11.0.sql @@ -0,0 +1,7799 @@ +-- Migration ladder as RESOLVED by the release this fixture is named for — every rung's +-- SQL frozen as that era's code (including its generators) emitted it, plus the same +-- version-table DDL and stamps MigrateLockedAsync writes. Generated by tools/generate- +-- ladder-fixture; regenerate at each release cut from the release tag. DO NOT HAND-EDIT. +-- ===BATCH=== bootstrap +SET search_path = collect, config, public; +CREATE TABLE IF NOT EXISTS darling_schema_version ( + version integer NOT NULL PRIMARY KEY, + name text NOT NULL, + applied_at timestamp NOT NULL +); +-- ===BATCH=== V1 collector-tables +/* Darling collector tables — generated from PerformanceMonitor.Collectors definitions. + Column names and types mirror Lite's DuckDB schema (see PgSchemaGenerator remarks). */ + +CREATE TABLE IF NOT EXISTS wait_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + wait_type text, + waiting_tasks_count bigint, + wait_time_ms bigint, + signal_wait_time_ms bigint, + delta_waiting_tasks bigint, + delta_wait_time_ms bigint, + delta_signal_wait_time_ms bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_wait_stats_time ON wait_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS latch_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + latch_class text, + waiting_requests_count bigint, + wait_time_ms bigint, + max_wait_time_ms bigint, + delta_waiting_requests_count bigint, + delta_wait_time_ms bigint, + delta_max_wait_time_ms bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_latch_stats_time ON latch_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS spinlock_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + spinlock_name text, + collisions bigint, + spins bigint, + spins_per_collision double precision, + sleep_time bigint, + backoffs bigint, + delta_collisions bigint, + delta_spins bigint, + delta_sleep_time bigint, + delta_backoffs bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_spinlock_stats_time ON spinlock_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS cpu_scheduler_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + max_workers_count integer, + scheduler_count integer, + cpu_count integer, + total_runnable_tasks_count integer, + total_work_queue_count bigint, + total_current_workers_count integer, + avg_runnable_tasks_count numeric(38,2), + total_active_request_count integer, + total_queued_request_count integer, + total_blocked_task_count integer, + total_active_parallel_thread_count bigint, + runnable_request_count integer, + total_request_count integer, + runnable_percent numeric(38,2), + worker_thread_exhaustion_warning boolean, + runnable_tasks_warning boolean, + blocked_tasks_warning boolean, + queued_requests_warning boolean, + total_physical_memory_kb bigint, + available_physical_memory_kb bigint, + system_memory_state_desc text, + physical_memory_pressure_warning boolean, + total_node_count integer, + nodes_online_count integer, + offline_cpu_count integer, + offline_cpu_warning boolean +); +CREATE INDEX IF NOT EXISTS idx_cpu_scheduler_stats_time ON cpu_scheduler_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS plan_cache_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + cacheobjtype text, + objtype text, + total_plans integer, + total_size_mb integer, + single_use_plans integer, + single_use_size_mb integer, + multi_use_plans integer, + multi_use_size_mb integer, + avg_use_count numeric(38,2), + avg_size_kb integer, + oldest_plan_create_time timestamp +); +CREATE INDEX IF NOT EXISTS idx_plan_cache_stats_time ON plan_cache_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS tempdb_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + user_object_reserved_mb numeric(18,2), + internal_object_reserved_mb numeric(18,2), + version_store_reserved_mb numeric(18,2), + total_reserved_mb numeric(18,2), + unallocated_mb numeric(18,2), + total_sessions_using_tempdb bigint, + top_session_id integer, + top_session_tempdb_mb numeric(18,2), + max_size_mb numeric(18,2) +); +CREATE INDEX IF NOT EXISTS idx_tempdb_stats_time ON tempdb_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS memory_grant_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + resource_semaphore_id smallint, + pool_id integer, + target_memory_mb numeric(18,2), + max_target_memory_mb numeric(18,2), + total_memory_mb numeric(18,2), + available_memory_mb numeric(18,2), + granted_memory_mb numeric(18,2), + used_memory_mb numeric(18,2), + grantee_count integer, + waiter_count integer, + timeout_error_count bigint, + forced_grant_count bigint, + timeout_error_count_delta bigint, + forced_grant_count_delta bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_memory_grant_stats_time ON memory_grant_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS cpu_utilization_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + sample_time timestamp, + sqlserver_cpu_utilization integer, + other_process_cpu_utilization integer, + sample_time_utc timestamp +); +CREATE INDEX IF NOT EXISTS idx_cpu_utilization_stats_time ON cpu_utilization_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS memory_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + total_physical_memory_mb numeric(18,2), + available_physical_memory_mb numeric(18,2), + total_page_file_mb numeric(18,2), + available_page_file_mb numeric(18,2), + system_memory_state text, + sql_memory_model text, + target_server_memory_mb numeric(18,2), + total_server_memory_mb numeric(18,2), + buffer_pool_mb numeric(18,2), + plan_cache_mb numeric(18,2), + max_workers_count integer, + current_workers_count integer +); +CREATE INDEX IF NOT EXISTS idx_memory_stats_time ON memory_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS memory_clerks ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + clerk_type text, + memory_mb numeric(18,2) +); +CREATE INDEX IF NOT EXISTS idx_memory_clerks_time ON memory_clerks(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS memory_pressure_events ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + sample_time timestamp, + memory_notification text, + memory_indicators_process integer, + memory_indicators_system integer +); +CREATE INDEX IF NOT EXISTS idx_memory_pressure_events_time ON memory_pressure_events(server_id, sample_time); + +CREATE TABLE IF NOT EXISTS file_io_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + file_name text, + file_type text, + physical_name text, + size_mb numeric(18,2), + num_of_reads bigint, + num_of_writes bigint, + read_bytes bigint, + write_bytes bigint, + io_stall_read_ms bigint, + io_stall_write_ms bigint, + io_stall_queued_read_ms bigint, + io_stall_queued_write_ms bigint, + delta_reads bigint, + delta_writes bigint, + delta_read_bytes bigint, + delta_write_bytes bigint, + delta_stall_read_ms bigint, + delta_stall_write_ms bigint, + delta_stall_queued_read_ms bigint, + delta_stall_queued_write_ms bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_file_io_stats_time ON file_io_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS server_properties ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + edition text, + product_version text, + product_level text, + product_update_level text, + engine_edition integer, + cpu_count integer, + hyperthread_ratio integer, + physical_memory_mb bigint, + socket_count integer, + cores_per_socket integer, + is_hadr_enabled boolean, + is_clustered boolean, + enterprise_features text, + service_objective text, + vcore_count integer, + lock_pages_in_memory boolean, + instant_file_initialization_enabled boolean, + memory_dump_count integer, + sqlserver_start_time timestamp, + host_os_version text, + ag_replica_role text, + utc_offset_minutes integer, + time_zone_id text +); +CREATE INDEX IF NOT EXISTS idx_server_properties_time ON server_properties(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS server_config ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + configuration_name text, + value_configured bigint, + value_in_use bigint, + is_dynamic boolean, + is_advanced boolean +); + +CREATE TABLE IF NOT EXISTS database_config ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + state_desc text, + compatibility_level integer, + collation_name text, + recovery_model text, + is_read_only boolean, + is_auto_close_on boolean, + is_auto_shrink_on boolean, + is_auto_create_stats_on boolean, + is_auto_update_stats_on boolean, + is_auto_update_stats_async_on boolean, + is_read_committed_snapshot_on boolean, + snapshot_isolation_state text, + is_parameterization_forced boolean, + is_query_store_on boolean, + is_encrypted boolean, + is_trustworthy_on boolean, + is_db_chaining_on boolean, + is_broker_enabled boolean, + is_cdc_enabled boolean, + is_mixed_page_allocation_on boolean, + log_reuse_wait_desc text, + page_verify_option text, + target_recovery_time_seconds integer, + delayed_durability text, + is_accelerated_database_recovery_on boolean, + is_memory_optimized_enabled boolean, + is_optimized_locking_on boolean +); + +CREATE TABLE IF NOT EXISTS database_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + database_id integer, + state_desc text, + is_in_standby boolean +); +CREATE INDEX IF NOT EXISTS idx_database_states_time ON database_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS trace_flags ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + trace_flag integer, + status boolean, + is_global boolean, + is_session boolean +); +CREATE INDEX IF NOT EXISTS idx_trace_flags_time ON trace_flags(server_id, capture_time); + +CREATE TABLE IF NOT EXISTS database_scoped_config ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + configuration_name text, + value text, + value_for_secondary text +); +CREATE INDEX IF NOT EXISTS idx_database_scoped_config_time ON database_scoped_config(server_id, capture_time); + +CREATE TABLE IF NOT EXISTS query_store_health ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + actual_state text, + desired_state text, + readonly_reason integer, + current_storage_size_mb bigint, + max_storage_size_mb bigint, + size_based_cleanup_mode text, + stale_query_threshold_days bigint, + max_plans_per_query bigint, + interval_length_minutes bigint, + query_capture_mode text, + wait_stats_capture_mode text +); +CREATE INDEX IF NOT EXISTS idx_query_store_health_time ON query_store_health(server_id, capture_time); + +CREATE TABLE IF NOT EXISTS session_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + program_name text, + connection_count bigint, + running_count integer, + sleeping_count integer, + dormant_count integer, + total_cpu_time_ms bigint, + total_reads bigint, + total_writes bigint, + total_logical_reads bigint +); +CREATE INDEX IF NOT EXISTS idx_session_stats_time ON session_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS session_summary_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + total_sessions integer, + running_sessions integer, + sleeping_sessions integer, + background_sessions integer, + dormant_sessions integer, + idle_sessions_over_30min integer, + sessions_waiting_for_memory integer, + databases_with_connections integer, + top_application_name text, + top_application_connections integer, + top_host_name text, + top_host_connections integer +); +CREATE INDEX IF NOT EXISTS idx_session_summary_stats_time ON session_summary_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS waiting_tasks ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + session_id integer, + wait_type text, + wait_duration_ms bigint, + blocking_session_id integer, + resource_description text, + database_name text +); +CREATE INDEX IF NOT EXISTS idx_waiting_tasks_time ON waiting_tasks(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS procedure_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + object_name text, + object_type text, + cached_time timestamp, + last_execution_time timestamp, + execution_count bigint, + total_worker_time bigint, + total_elapsed_time bigint, + total_logical_reads bigint, + total_physical_reads bigint, + total_logical_writes bigint, + min_worker_time bigint, + max_worker_time bigint, + min_elapsed_time bigint, + max_elapsed_time bigint, + min_logical_reads bigint, + max_logical_reads bigint, + min_physical_reads bigint, + max_physical_reads bigint, + min_logical_writes bigint, + max_logical_writes bigint, + total_spills bigint, + min_spills bigint, + max_spills bigint, + sql_handle text, + plan_handle text, + delta_execution_count bigint, + delta_worker_time bigint, + delta_elapsed_time bigint, + delta_logical_reads bigint, + delta_logical_writes bigint, + delta_physical_reads bigint, + delta_spills bigint, + query_plan_xml text, + query_plan_xml_bytes bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_procedure_stats_time ON procedure_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS running_jobs ( + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + job_name text, + job_id text, + job_enabled boolean, + start_time timestamp, + current_duration_seconds bigint, + avg_duration_seconds bigint, + p95_duration_seconds bigint, + successful_run_count bigint, + is_running_long boolean, + percent_of_average numeric(10,1) +); +CREATE INDEX IF NOT EXISTS idx_running_jobs_time ON running_jobs(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS perfmon_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + object_name text, + counter_name text, + instance_name text, + cntr_value bigint, + delta_cntr_value bigint, + sample_interval_seconds integer, + cntr_type integer +); +CREATE INDEX IF NOT EXISTS idx_perfmon_stats_time ON perfmon_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS dmv_blocking_snapshots ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + monitor_loop integer, + event_time timestamp, + database_name text, + blocked_spid integer, + blocked_ecid integer, + blocked_last_tran_started timestamp, + blocking_spid integer, + blocking_ecid integer, + blocking_last_tran_started timestamp, + wait_time_ms bigint, + lock_mode text, + blocking_status text, + contentious_object text, + blocked_sql_text text, + blocking_sql_text text, + blocked_login_name text, + blocked_host_name text, + blocked_client_app text, + blocking_login_name text, + blocking_host_name text, + blocking_client_app text, + blocking_login_time timestamp, + blocking_last_request_end_time timestamp, + blocking_open_transaction_count integer, + blocking_tran_log_bytes_used bigint +); +CREATE INDEX IF NOT EXISTS idx_dmv_blocking_snapshots_time ON dmv_blocking_snapshots(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS database_size_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + database_id integer, + file_id integer, + file_type_desc text, + file_name text, + physical_name text, + total_size_mb numeric(19,2), + used_size_mb numeric(19,2), + auto_growth_mb numeric(19,2), + max_size_mb numeric(19,2), + recovery_model_desc text, + compatibility_level integer, + state_desc text, + volume_mount_point text, + volume_total_mb numeric(19,2), + volume_free_mb numeric(19,2), + is_percent_growth boolean, + growth_pct integer, + vlf_count integer +); +CREATE INDEX IF NOT EXISTS idx_database_size_stats_time ON database_size_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS index_object_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + sqlserver_start_time timestamp, + database_name text, + database_id integer, + schema_name text, + object_id integer, + table_name text, + index_id integer, + index_name text, + index_type_desc text, + is_unique boolean, + is_primary_key boolean, + is_filtered boolean, + partition_count integer, + reserved_mb numeric(19,2), + used_mb numeric(19,2), + in_row_data_mb numeric(19,2), + lob_data_mb numeric(19,2), + row_overflow_mb numeric(19,2), + total_rows bigint, + user_seeks bigint, + user_scans bigint, + user_lookups bigint, + user_updates bigint, + last_user_seek timestamp, + last_user_scan timestamp, + last_user_lookup timestamp, + last_user_update timestamp, + leaf_insert_count bigint, + leaf_update_count bigint, + leaf_delete_count bigint, + range_scan_count bigint, + singleton_lookup_count bigint, + row_lock_count bigint, + row_lock_wait_count bigint, + row_lock_wait_in_ms bigint, + page_lock_count bigint, + page_lock_wait_count bigint, + page_lock_wait_in_ms bigint, + index_lock_promotion_attempt_count bigint, + index_lock_promotion_count bigint, + page_latch_wait_count bigint, + page_latch_wait_in_ms bigint, + page_io_latch_wait_count bigint, + page_io_latch_wait_in_ms bigint, + key_columns text, + included_columns text, + filter_definition text, + is_unique_constraint boolean, + is_foreign_key boolean, + is_foreign_key_reference boolean, + is_disabled boolean, + data_compression_desc text, + optimize_for_sequential_key boolean, + fill_factor smallint, + is_padded boolean, + allow_page_locks boolean, + allow_row_locks boolean, + is_indexed_view boolean +); +CREATE INDEX IF NOT EXISTS idx_index_object_stats_object ON index_object_stats(server_id, database_name, object_id, index_id, collection_time); + +CREATE TABLE IF NOT EXISTS query_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + query_hash text, + query_plan_hash text, + creation_time timestamp, + last_execution_time timestamp, + execution_count bigint, + total_worker_time bigint, + total_elapsed_time bigint, + total_logical_reads bigint, + total_logical_writes bigint, + total_physical_reads bigint, + total_clr_time bigint, + total_rows bigint, + total_spills bigint, + min_worker_time bigint, + max_worker_time bigint, + min_elapsed_time bigint, + max_elapsed_time bigint, + min_physical_reads bigint, + max_physical_reads bigint, + min_rows bigint, + max_rows bigint, + min_dop bigint, + max_dop bigint, + min_grant_kb bigint, + max_grant_kb bigint, + min_used_grant_kb bigint, + max_used_grant_kb bigint, + min_ideal_grant_kb bigint, + max_ideal_grant_kb bigint, + min_reserved_threads bigint, + max_reserved_threads bigint, + min_used_threads bigint, + max_used_threads bigint, + min_spills bigint, + max_spills bigint, + query_text text, + query_plan_xml text, + sql_handle text, + plan_handle text, + delta_execution_count bigint, + delta_worker_time bigint, + delta_elapsed_time bigint, + delta_logical_reads bigint, + delta_logical_writes bigint, + delta_physical_reads bigint, + delta_rows bigint, + delta_spills bigint, + plan_generation_num bigint, + sample_interval_seconds integer, + host_object_name text, + query_plan_xml_bytes bigint, + statement_start_offset integer, + statement_end_offset integer +); +CREATE INDEX IF NOT EXISTS idx_query_stats_time ON query_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS query_snapshots ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + session_id integer, + database_name text, + elapsed_time_formatted text, + query_text text, + query_plan text, + live_query_plan text, + status text, + blocking_session_id integer, + wait_type text, + wait_time_ms bigint, + wait_resource text, + cpu_time_ms bigint, + total_elapsed_time_ms bigint, + reads bigint, + writes bigint, + logical_reads bigint, + granted_query_memory_gb numeric(18,2), + transaction_isolation_level text, + dop integer, + parallel_worker_count integer, + login_name text, + host_name text, + program_name text, + open_transaction_count integer, + percent_complete numeric(5,2), + is_cdc_capture boolean, + query_hash text, + requested_memory_mb double precision, + used_memory_mb double precision, + max_used_memory_mb double precision, + tempdb_current_mb double precision, + tempdb_allocations_mb double precision, + tran_log_used_mb double precision, + tran_start_time timestamp, + request_id integer +); +CREATE INDEX IF NOT EXISTS idx_query_snapshots_time ON query_snapshots(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS query_store_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + execution_type_desc text, + first_execution_time timestamp, + last_execution_time timestamp, + module_name text, + query_text text, + query_hash text, + execution_count bigint, + avg_duration_us bigint, + min_duration_us bigint, + max_duration_us bigint, + avg_cpu_time_us bigint, + min_cpu_time_us bigint, + max_cpu_time_us bigint, + avg_logical_io_reads bigint, + min_logical_io_reads bigint, + max_logical_io_reads bigint, + avg_logical_io_writes bigint, + min_logical_io_writes bigint, + max_logical_io_writes bigint, + avg_physical_io_reads bigint, + min_physical_io_reads bigint, + max_physical_io_reads bigint, + avg_clr_time_us bigint, + min_clr_time_us bigint, + max_clr_time_us bigint, + min_dop bigint, + max_dop bigint, + avg_query_max_used_memory bigint, + min_query_max_used_memory bigint, + max_query_max_used_memory bigint, + avg_rowcount bigint, + min_rowcount bigint, + max_rowcount bigint, + avg_num_physical_io_reads bigint, + min_num_physical_io_reads bigint, + max_num_physical_io_reads bigint, + avg_log_bytes_used bigint, + min_log_bytes_used bigint, + max_log_bytes_used bigint, + avg_tempdb_space_used bigint, + min_tempdb_space_used bigint, + max_tempdb_space_used bigint, + plan_type text, + plan_forcing_type text, + is_forced_plan boolean, + force_failure_count bigint, + last_force_failure_reason text, + compatibility_level integer, + query_plan_text text, + query_plan_hash text, + replica_role text, + runtime_stats_interval_id bigint, + interval_start_time_utc timestamp, + interval_end_time_utc timestamp +); +CREATE INDEX IF NOT EXISTS idx_query_store_stats_time ON query_store_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS deadlocks ( + deadlock_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + deadlock_time timestamp, + victim_process_id text, + victim_sql_text text, + deadlock_graph_xml text, + victim_query_plan_xml text, + database_name text +); +CREATE INDEX IF NOT EXISTS idx_deadlocks_time ON deadlocks(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS blocked_process_reports ( + blocked_report_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + database_name text, + blocked_spid integer, + blocked_ecid integer, + blocking_spid integer, + blocking_ecid integer, + wait_time_ms bigint, + wait_resource text, + lock_mode text, + blocked_status text, + blocked_isolation_level text, + blocked_log_used bigint, + blocked_transaction_count integer, + blocked_client_app text, + blocked_host_name text, + blocked_login_name text, + blocked_sql_text text, + blocking_status text, + blocking_isolation_level text, + blocking_client_app text, + blocking_host_name text, + blocking_login_name text, + blocking_sql_text text, + blocked_transaction_name text, + blocking_transaction_name text, + blocked_last_tran_started timestamp, + blocking_last_tran_started timestamp, + blocked_last_batch_started timestamp, + blocking_last_batch_started timestamp, + blocked_last_batch_completed timestamp, + blocking_last_batch_completed timestamp, + blocked_priority integer, + blocking_priority integer, + blocked_process_report_xml text, + object_id integer, + database_id integer, + contentious_object text, + monitor_loop integer, + blocked_query_plan_xml text, + blocking_query_plan_xml text +); +CREATE INDEX IF NOT EXISTS idx_blocked_process_reports_time ON blocked_process_reports(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS attention_events ( + attention_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_kind text, + attention_count bigint, + database_name text, + client_app_name text, + client_hostname text, + session_id integer, + request_id integer, + interrupt_duration_us bigint, + statement_fingerprint text, + statement_text text +); +CREATE INDEX IF NOT EXISTS idx_attention_events_time ON attention_events(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS long_query_completions ( + long_query_completion_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_type text, + database_id integer, + database_name text, + session_id integer, + client_app_name text, + client_pid integer, + nt_username text, + server_principal_name text, + query_hash text, + event_sequence bigint, + duration_microseconds bigint, + cpu_time_microseconds bigint, + physical_reads bigint, + logical_reads bigint, + writes bigint, + row_count bigint, + result text, + statement_text text, + object_name text +); +CREATE INDEX IF NOT EXISTS idx_long_query_completions_time ON long_query_completions(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS system_health_events ( + system_health_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_type text, + event_xml text +); +CREATE INDEX IF NOT EXISTS idx_system_health_events_time ON system_health_events(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS default_trace_events ( + default_trace_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_name text, + event_class integer, + spid integer, + database_name text, + database_id integer, + login_name text, + host_name text, + application_name text, + object_name text, + filename text, + integer_data bigint, + integer_data_2 bigint, + text_data text, + session_login_name text, + error_number integer, + severity integer, + state integer, + event_sequence bigint, + duration_us bigint, + end_time timestamp +); +CREATE INDEX IF NOT EXISTS idx_default_trace_events_time ON default_trace_events(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS job_history ( + job_history_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + instance_id bigint, + job_id text, + job_name text, + job_enabled boolean, + category_name text, + step_id integer, + step_name text, + run_status integer, + run_status_desc text, + run_datetime timestamp, + run_duration_seconds bigint, + retries_attempted integer, + message text +); +CREATE INDEX IF NOT EXISTS idx_job_history_time ON job_history(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS agent_status ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + agent_running boolean, + agent_status_desc text, + agent_startup_desc text, + next_scheduled_run timestamp +); +CREATE INDEX IF NOT EXISTS idx_agent_status_time ON agent_status(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS ag_replica_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + ag_name text, + replica_server_name text, + role_desc text, + operational_state_desc text, + connected_state_desc text, + recovery_health_desc text, + synchronization_health_desc text, + availability_mode_desc text, + failover_mode_desc text, + endpoint_url text, + is_local boolean, + group_id text, + primary_replica text +); +CREATE INDEX IF NOT EXISTS idx_ag_replica_states_time ON ag_replica_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS ag_database_replica_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + ag_name text, + database_name text, + replica_server_name text, + is_local boolean, + synchronization_state_desc text, + last_hardened_lsn text, + last_commit_lsn text, + log_send_queue_size bigint, + redo_queue_size bigint, + log_send_rate bigint, + redo_rate bigint, + is_suspended boolean, + suspend_reason_desc text, + availability_mode_desc text, + secondary_lag_seconds bigint, + last_commit_time timestamp, + last_hardened_time timestamp, + last_redone_time timestamp, + last_received_time timestamp, + est_redo_completion_time_min double precision, + est_send_drain_time_min double precision, + group_id text +); +CREATE INDEX IF NOT EXISTS idx_ag_database_replica_states_time ON ag_database_replica_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS plan_correction ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + force_last_good_plan_desired_state text, + force_last_good_plan_actual_state text, + force_last_good_plan_reason text, + create_index_actual_state text, + drop_index_actual_state text, + recommendation_name text, + recommendation_type text, + recommendation_state text, + recommendation_state_reason text, + recommendation_reason text, + valid_since timestamp, + last_refresh timestamp, + score integer, + query_id bigint, + query_text text, + regressed_plan_id bigint, + last_good_plan_id bigint, + last_good_plan_forcing_type text, + last_good_plan_is_forced boolean, + last_good_plan_force_failure_reason text, + regressed_plan_execution_count bigint, + regressed_plan_cpu_time_average_ms double precision, + regressed_plan_error_count bigint, + last_good_plan_execution_count bigint, + last_good_plan_cpu_time_average_ms double precision, + last_good_plan_error_count bigint, + estimated_gain_seconds double precision, + is_executable_action boolean, + is_revertable_action boolean, + execute_action_initiated_by text, + execute_action_initiated_time timestamp, + execute_action_start_time timestamp, + execute_action_duration_seconds double precision, + revert_action_initiated_by text, + revert_action_initiated_time timestamp, + revert_action_start_time timestamp, + revert_action_duration_seconds double precision, + implementation_script text +); +CREATE INDEX IF NOT EXISTS idx_plan_correction_time ON plan_correction(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS query_store_forced_plans ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + plan_id bigint, + query_id bigint, + query_plan_hash text, + plan_forcing_type text, + force_failure_count bigint, + last_force_failure_reason text, + last_execution_time timestamp, + last_compile_start_time timestamp, + variant_plan_ids text, + plan_guide_name text, + plan_guide_enabled boolean, + plan_guide_scope text +); +CREATE INDEX IF NOT EXISTS idx_query_store_forced_plans_time ON query_store_forced_plans(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pvs_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + database_id integer, + is_accelerated_database_recovery_on boolean, + pvs_filegroup_id smallint, + persistent_version_store_size_mb numeric(19,2), + online_index_version_store_size_mb numeric(19,2), + database_data_size_mb numeric(19,2), + current_aborted_transaction_count bigint, + oldest_active_transaction_id bigint, + oldest_aborted_transaction_id bigint, + min_transaction_timestamp bigint, + online_index_min_transaction_timestamp bigint, + secondary_low_water_mark bigint, + offrow_version_cleaner_start_time timestamp, + offrow_version_cleaner_end_time timestamp, + aborted_version_cleaner_start_time timestamp, + aborted_version_cleaner_end_time timestamp, + pvs_off_row_page_skipped_low_water_mark bigint, + pvs_off_row_page_skipped_transaction_not_cleaned bigint, + pvs_off_row_page_skipped_oldest_active_xdesid bigint, + pvs_off_row_page_skipped_min_useful_xts bigint, + pvs_off_row_page_skipped_oldest_snapshot bigint, + pvs_off_row_page_skipped_oldest_aborted_xdesid bigint +); +CREATE INDEX IF NOT EXISTS idx_pvs_stats_time ON pvs_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_wait_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + wait_type_id integer, + wait_event_id bigint, + wait_type text, + wait_event text, + waits bigint, + wait_time_us bigint, + delta_waits bigint, + delta_wait_time_us bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_pg_wait_stats_time ON pg_wait_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_statement_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + queryid bigint, + database_id bigint, + user_id bigint, + toplevel boolean, + calls bigint, + total_exec_time_ms double precision, + min_exec_time_ms double precision, + max_exec_time_ms double precision, + mean_exec_time_ms double precision, + rows_returned bigint, + shared_blks_hit bigint, + shared_blks_read bigint, + shared_blks_dirtied bigint, + shared_blks_written bigint, + temp_blks_read bigint, + temp_blks_written bigint, + blk_read_time_ms double precision, + blk_write_time_ms double precision, + storage_blks_read bigint, + orcache_blks_hit bigint, + storage_blk_read_time_ms double precision, + orcache_blk_read_time_ms double precision, + wal_records bigint, + wal_fpi bigint, + wal_bytes bigint, + total_exec_peakmem_bytes bigint, + max_exec_peakmem_bytes bigint, + delta_calls bigint, + delta_total_exec_time_ms bigint, + delta_rows bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_pg_statement_stats_time ON pg_statement_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_wraparound_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + frozen_xid_age bigint, + min_multixid_age bigint, + autovacuum_freeze_max_age bigint, + autovacuum_multixact_freeze_max_age bigint, + pct_toward_emergency_vacuum double precision, + pct_toward_wraparound double precision, + pct_toward_multixact_emergency double precision, + pct_toward_multixact_wraparound double precision, + xids_remaining bigint, + multixids_remaining bigint, + allows_connections boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_wraparound_stats_time ON pg_wraparound_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_server_config ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + name text, + setting text, + unit text, + category text, + context text, + vartype text, + source text, + boot_val text, + reset_val text, + sourcefile text, + sourceline integer, + pending_restart boolean, + short_desc text, + database_name text, + role_name text +); +CREATE INDEX IF NOT EXISTS idx_pg_server_config_time ON pg_server_config(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_deadlocks ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + occurred_at timestamp, + victim_pid integer, + participant_count integer, + deadlock_hash text, + lock_modes text, + resources text, + victim_statement text, + graph_text text +); +CREATE INDEX IF NOT EXISTS idx_pg_deadlocks_time ON pg_deadlocks(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_log_events ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + occurred_at timestamp, + family text, + severity text, + sqlstate text, + database_name text, + user_name text, + application_name text, + pid integer, + message text, + detail text, + context text, + statement_fingerprint text, + raw_line_hash text, + relation_name text, + bytes bigint, + duration_ms bigint, + pages_removed bigint, + pages_remaining bigint, + tuples_removed bigint, + tuples_remaining bigint, + buffer_hits bigint, + buffer_misses bigint, + buffer_dirtied bigint, + wal_records bigint, + wal_bytes bigint, + is_analyze boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_log_events_time ON pg_log_events(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_xmin_horizon ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + source text, + xmin_age bigint, + holder text, + detail text, + is_winner boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_xmin_horizon_time ON pg_xmin_horizon(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_replication_slot_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + slot_name text, + slot_type text, + plugin text, + database_name text, + is_active boolean, + active_pid bigint, + is_temporary boolean, + two_phase boolean, + wal_status text, + safe_wal_size_bytes bigint, + retained_wal_bytes bigint, + xmin_age bigint, + catalog_xmin_age bigint, + inactive_since timestamp, + invalidation_reason text, + conflicting boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_replication_slot_stats_time ON pg_replication_slot_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_autovacuum_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + live_tuples bigint, + dead_tuples bigint, + mods_since_analyze bigint, + inserts_since_vacuum bigint, + vacuum_threshold bigint, + insert_vacuum_threshold bigint, + analyze_threshold bigint, + autovacuum_disabled boolean, + total_bytes bigint, + last_vacuum timestamp, + last_autovacuum timestamp, + last_analyze timestamp, + last_autoanalyze timestamp, + vacuum_count bigint, + autovacuum_count bigint, + analyze_count bigint, + autoanalyze_count bigint +); +CREATE INDEX IF NOT EXISTS idx_pg_autovacuum_stats_time ON pg_autovacuum_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_io_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + backend_type text, + object_type text, + context text, + reads bigint, + read_time_ms double precision, + writes bigint, + write_time_ms double precision, + writebacks bigint, + writeback_time_ms double precision, + extends bigint, + extend_time_ms double precision, + op_bytes bigint, + hits bigint, + evictions bigint, + reuses bigint, + fsyncs bigint, + fsync_time_ms double precision, + stats_reset timestamp, + read_bytes numeric(28,0), + write_bytes numeric(28,0), + extend_bytes numeric(28,0) +); +CREATE INDEX IF NOT EXISTS idx_pg_io_stats_time ON pg_io_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_blocking_edges ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + blocked_backend_id bigint, + blocked_pid integer, + blocking_backend_id bigint, + blocking_pid integer, + database_name text, + blocked_username text, + blocked_application_name text, + blocked_client_addr text, + blocked_state text, + blocked_wait_event_type text, + blocked_wait_event text, + blocked_query text, + blocked_xact_duration_ms bigint, + blocked_query_duration_ms bigint, + blocking_username text, + blocking_application_name text, + blocking_client_addr text, + blocking_state text, + blocking_wait_event_type text, + blocking_wait_event text, + blocking_query text, + blocking_xact_duration_ms bigint, + blocking_query_duration_ms bigint, + blocked_pid_count integer, + blocking_is_idle_in_transaction boolean, + query_text_may_be_truncated boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_blocking_edges_time ON pg_blocking_edges(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_database_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + xact_commit bigint, + xact_rollback bigint, + blks_read bigint, + blks_hit bigint, + temp_files bigint, + temp_bytes bigint, + deadlocks bigint, + stats_reset timestamp, + numbackends integer +); +CREATE INDEX IF NOT EXISTS idx_pg_database_stats_time ON pg_database_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_index_usage_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + index_name text, + index_scans bigint, + tuples_read bigint, + tuples_fetched bigint, + blocks_read bigint, + blocks_hit bigint, + index_bytes bigint, + table_bytes bigint, + is_unique boolean, + is_primary_key boolean, + is_valid boolean, + is_ready boolean, + is_replica_identity boolean, + is_partial boolean, + is_expression boolean, + supports_constraint boolean, + index_method text, + column_count integer, + index_definition text, + last_scan timestamp, + stats_reset timestamp +); +CREATE INDEX IF NOT EXISTS idx_pg_index_usage_stats_time ON pg_index_usage_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_table_bloat_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + heap_bytes bigint, + heap_pages bigint, + toast_bytes bigint, + index_bytes bigint, + live_tuples bigint, + dead_tuples bigint, + mods_since_analyze bigint, + last_analyzed timestamp, + estimated_tuple_bytes double precision, + estimated_heap_pages bigint, + fillfactor integer, + bloat_bytes_estimate bigint, + bloat_pct_estimate numeric(5,2), + estimate_unavailable boolean, + alignment_bytes integer, + pgstattuple_available boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_table_bloat_stats_time ON pg_table_bloat_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_session_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + backend_id bigint, + pid integer, + database_name text, + username text, + application_name text, + client_addr text, + backend_type text, + state text, + wait_event_type text, + wait_event text, + command_tag text, + query_id bigint, + state_duration_ms bigint, + xact_duration_ms bigint, + query_duration_ms bigint, + backend_duration_ms bigint, + xmin_age bigint, + xid_age bigint, + horizon_age bigint, + is_idle_in_transaction boolean, + is_horizon_holder boolean, + state_is_redacted boolean, + total_sessions integer, + active_sessions integer, + idle_in_transaction_sessions integer, + reportable_sessions integer +); +CREATE INDEX IF NOT EXISTS idx_pg_session_states_time ON pg_session_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_plan_capture_readiness ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + facet text, + is_satisfied boolean, + observed text, + detail text +); +CREATE INDEX IF NOT EXISTS idx_pg_plan_capture_readiness_time ON pg_plan_capture_readiness(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_write_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + num_timed bigint, + num_requested bigint, + num_done bigint, + restartpoints_timed bigint, + restartpoints_req bigint, + restartpoints_done bigint, + checkpoint_write_time_ms double precision, + checkpoint_sync_time_ms double precision, + buffers_written_checkpoint bigint, + slru_written bigint, + checkpointer_stats_reset timestamp, + buffers_clean bigint, + maxwritten_clean bigint, + buffers_alloc bigint, + buffers_backend bigint, + buffers_backend_fsync bigint, + bgwriter_stats_reset timestamp, + wal_records bigint, + wal_fpi bigint, + wal_bytes numeric(38,0), + wal_buffers_full bigint, + wal_write bigint, + wal_sync bigint, + wal_write_time_ms double precision, + wal_sync_time_ms double precision, + wal_stats_reset timestamp, + postmaster_start_time timestamp +); +CREATE INDEX IF NOT EXISTS idx_pg_write_stats_time ON pg_write_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_extension_availability ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + extension_name text, + state text, + installed_version text, + default_version text, + is_monitoring_relevant boolean, + comment text +); +CREATE INDEX IF NOT EXISTS idx_pg_extension_availability_time ON pg_extension_availability(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_lock_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + lock_type text, + mode text, + granted boolean, + relation_oid bigint, + relation_name text, + backend_count bigint, + oldest_wait_ms double precision +); +CREATE INDEX IF NOT EXISTS idx_pg_lock_stats_time ON pg_lock_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_wait_sampling ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_type text, + event text, + query_id bigint, + sample_count bigint, + profile_period_ms integer, + backend_count integer, + sampled_ms integer +); +CREATE INDEX IF NOT EXISTS idx_pg_wait_sampling_time ON pg_wait_sampling(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_kernel_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + query_id bigint, + exec_user_time_ms double precision, + exec_system_time_ms double precision, + plan_cpu_time_ms double precision, + exec_read_bytes bigint, + exec_write_bytes bigint, + minor_faults bigint, + major_faults bigint, + stats_since timestamp +); +CREATE INDEX IF NOT EXISTS idx_pg_kernel_stats_time ON pg_kernel_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_predicate_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + column_name text, + operator text, + query_id bigint, + sample_count bigint, + rows_evaluated bigint, + rows_filtered bigint, + worst_estimate_error_ratio double precision, + sample_rate double precision +); +CREATE INDEX IF NOT EXISTS idx_pg_predicate_stats_time ON pg_predicate_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_plan_capture ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + query_id bigint, + plan_hash text, + duration_ms double precision, + node_count integer, + top_node_type text, + plan_json text +); +CREATE INDEX IF NOT EXISTS idx_pg_plan_capture_time ON pg_plan_capture(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_column_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + column_name text, + n_distinct double precision, + null_frac double precision, + avg_width integer, + correlation double precision, + top_value_frequency double precision, + common_value_count integer +); +CREATE INDEX IF NOT EXISTS idx_pg_column_stats_time ON pg_column_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_replication_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + application_name text, + client_addr text, + state text, + sync_state text, + sync_priority integer, + sent_bytes_behind bigint, + write_bytes_behind bigint, + flush_bytes_behind bigint, + replay_bytes_behind bigint, + write_lag_ms double precision, + flush_lag_ms double precision, + replay_lag_ms double precision, + backend_start timestamp +); +CREATE INDEX IF NOT EXISTS idx_pg_replication_stats_time ON pg_replication_stats(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_buffer_usage ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + relation_name text, + relation_kind text, + buffers bigint, + dirty_buffers bigint, + avg_usage_count double precision, + pool_buffers_total bigint, + pool_buffers_used bigint +); +CREATE INDEX IF NOT EXISTS idx_pg_buffer_usage_time ON pg_buffer_usage(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_index_bloat ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + index_name text, + index_bytes bigint, + tree_level integer, + internal_pages bigint, + leaf_pages bigint, + empty_pages bigint, + deleted_pages bigint, + avg_leaf_density double precision, + leaf_fragmentation double precision, + skipped_reason text, + index_pages bigint, + table_rows bigint, + fillfactor integer, + est_tuple_bytes bigint, + est_leaf_pages bigint, + est_bloat_pct double precision, + est_reclaimable_bytes bigint, + pgstattuple_available boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_index_bloat_time ON pg_index_bloat(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_cpu_utilization ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + sample_time timestamp, + cpu_percent double precision, + acu_utilization_percent double precision, + serverless_capacity_acu double precision, + max_configured_acu double precision, + memory_total_bytes bigint, + memory_free_bytes bigint, + memory_cached_bytes bigint, + memory_buffers_bytes bigint, + memory_active_bytes bigint, + configured_memory_bytes bigint +); +CREATE INDEX IF NOT EXISTS idx_pg_cpu_utilization_time ON pg_cpu_utilization(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS pg_database_size_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + size_bytes bigint, + total_bytes bigint, + is_template boolean, + allows_connections boolean +); +CREATE INDEX IF NOT EXISTS idx_pg_database_size_stats_time ON pg_database_size_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (1, 'collector-tables', now()::timestamp); +-- ===BATCH=== V2 server-registry-and-collection-log + +CREATE TABLE IF NOT EXISTS servers ( + server_id integer NOT NULL PRIMARY KEY, + server_name text NOT NULL, + display_name text, + is_enabled boolean NOT NULL DEFAULT TRUE, + sql_engine_edition integer, + sql_major_version integer, + created_date timestamp, + modified_date timestamp +); + +CREATE TABLE IF NOT EXISTS collection_log ( + log_id bigint NOT NULL, + server_id integer NOT NULL, + server_name text, + collector_name text NOT NULL, + collection_time timestamp NOT NULL, + duration_ms integer, + status text NOT NULL, + error_message text, + rows_collected integer, + sql_duration_ms integer, + duckdb_duration_ms integer +); + +CREATE INDEX IF NOT EXISTS idx_collection_log_time ON collection_log(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (2, 'server-registry-and-collection-log', now()::timestamp); +-- ===BATCH=== V3 alerting-stores + +CREATE TABLE IF NOT EXISTS config_alert_log ( + alert_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + metric_name text NOT NULL, + current_value double precision NOT NULL, + threshold_value double precision NOT NULL, + alert_sent boolean NOT NULL DEFAULT FALSE, + notification_type text NOT NULL DEFAULT 'tray', + send_error text, + dismissed boolean NOT NULL DEFAULT FALSE, + muted boolean NOT NULL DEFAULT FALSE, + detail_text text, + context_json text +); + +CREATE INDEX IF NOT EXISTS idx_config_alert_log_time ON config_alert_log(server_id, metric_name, alert_time); + +CREATE TABLE IF NOT EXISTS config_edge_trigger_watermarks ( + server_id integer NOT NULL, + metric_name text NOT NULL, + watermark integer NOT NULL, + watermark_time timestamp, + updated_at timestamp NOT NULL, + PRIMARY KEY (server_id, metric_name) +); + +CREATE TABLE IF NOT EXISTS config_mute_rules ( + id text NOT NULL PRIMARY KEY, + enabled boolean NOT NULL DEFAULT TRUE, + created_at_utc timestamp NOT NULL, + expires_at_utc timestamp, + reason text, + server_name text, + metric_name text, + database_pattern text, + query_text_pattern text, + wait_type_pattern text, + job_name_pattern text +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (3, 'alerting-stores', now()::timestamp); +-- ===BATCH=== V4 analysis-tables + +CREATE TABLE IF NOT EXISTS analysis_findings ( + finding_id bigint NOT NULL, + analysis_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + time_range_start timestamp, + time_range_end timestamp, + severity double precision NOT NULL, + confidence double precision NOT NULL, + category text NOT NULL, + story_path text NOT NULL, + story_path_hash text NOT NULL, + story_text text NOT NULL, + root_fact_key text NOT NULL, + root_fact_value double precision, + leaf_fact_key text, + leaf_fact_value double precision, + fact_count integer NOT NULL, + incident_id text, + remediation_action_json text +); + +CREATE INDEX IF NOT EXISTS idx_analysis_findings_time ON analysis_findings(server_id, analysis_time); +CREATE INDEX IF NOT EXISTS idx_analysis_findings_hash ON analysis_findings(story_path_hash); + +CREATE TABLE IF NOT EXISTS analysis_muted ( + mute_id bigint NOT NULL PRIMARY KEY, + server_id integer, + database_name text, + story_path_hash text NOT NULL, + story_path text NOT NULL, + muted_date timestamp NOT NULL, + reason text +); + +CREATE INDEX IF NOT EXISTS idx_analysis_muted_hash ON analysis_muted(story_path_hash); + +CREATE OR REPLACE VIEW v_wait_stats AS SELECT * FROM wait_stats; +CREATE OR REPLACE VIEW v_query_stats AS SELECT * FROM query_stats; +CREATE OR REPLACE VIEW v_query_store_stats AS SELECT * FROM query_store_stats; +CREATE OR REPLACE VIEW v_cpu_utilization_stats AS SELECT * FROM cpu_utilization_stats; +CREATE OR REPLACE VIEW v_memory_grant_stats AS SELECT * FROM memory_grant_stats; +CREATE OR REPLACE VIEW v_memory_stats AS SELECT * FROM memory_stats; +CREATE OR REPLACE VIEW v_perfmon_stats AS SELECT * FROM perfmon_stats; +CREATE OR REPLACE VIEW v_session_stats AS SELECT * FROM session_stats; +CREATE OR REPLACE VIEW v_file_io_stats AS SELECT * FROM file_io_stats; +CREATE OR REPLACE VIEW v_blocked_process_reports AS SELECT * FROM blocked_process_reports; +CREATE OR REPLACE VIEW v_deadlocks AS SELECT * FROM deadlocks; +CREATE OR REPLACE VIEW v_dmv_blocking_snapshots AS SELECT * FROM dmv_blocking_snapshots; +CREATE OR REPLACE VIEW v_index_object_stats AS SELECT * FROM index_object_stats; +CREATE OR REPLACE VIEW v_database_size_stats AS SELECT * FROM database_size_stats; +CREATE OR REPLACE VIEW v_tempdb_stats AS SELECT * FROM tempdb_stats; +CREATE OR REPLACE VIEW v_query_snapshots AS SELECT * FROM query_snapshots; +CREATE OR REPLACE VIEW v_database_config AS SELECT * FROM database_config; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (4, 'analysis-tables', now()::timestamp); +-- ===BATCH=== V5 viewer-passthrough-views + +CREATE OR REPLACE VIEW v_running_jobs AS SELECT * FROM running_jobs; +CREATE OR REPLACE VIEW v_server_config AS SELECT * FROM server_config; +CREATE OR REPLACE VIEW v_database_scoped_config AS SELECT * FROM database_scoped_config; +CREATE OR REPLACE VIEW v_trace_flags AS SELECT * FROM trace_flags; +CREATE OR REPLACE VIEW v_collection_log AS SELECT * FROM collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (5, 'viewer-passthrough-views', now()::timestamp); +-- ===BATCH=== V6 memory-tab-passthrough-views + +CREATE OR REPLACE VIEW v_memory_clerks AS SELECT * FROM memory_clerks; +CREATE OR REPLACE VIEW v_memory_pressure_events AS SELECT * FROM memory_pressure_events; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (6, 'memory-tab-passthrough-views', now()::timestamp); +-- ===BATCH=== V7 viewer-plan-capture-columns + +ALTER TABLE procedure_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE blocked_process_reports ADD COLUMN IF NOT EXISTS blocked_query_plan_xml text; +ALTER TABLE blocked_process_reports ADD COLUMN IF NOT EXISTS blocking_query_plan_xml text; +ALTER TABLE deadlocks ADD COLUMN IF NOT EXISTS victim_query_plan_xml text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (7, 'viewer-plan-capture-columns', now()::timestamp); +-- ===BATCH=== V8 schema-split-collect-config +/* V8: split public into collect/config (Darling security hardening, #1262). + Table NAMES are unchanged; search_path = collect, config, public resolves the bare + references every SQL site already uses, so no query is re-qualified. */ + +CREATE SCHEMA IF NOT EXISTS collect AUTHORIZATION darling; +CREATE SCHEMA IF NOT EXISTS config AUTHORIZATION darling; + +/* collect: all collector tables (from the catalog) + registry/metadata + the V4-V6 views */ +ALTER TABLE IF EXISTS public.wait_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.latch_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.spinlock_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.cpu_scheduler_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.plan_cache_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.tempdb_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.memory_grant_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.cpu_utilization_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.memory_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.memory_clerks SET SCHEMA collect; +ALTER TABLE IF EXISTS public.memory_pressure_events SET SCHEMA collect; +ALTER TABLE IF EXISTS public.file_io_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.server_properties SET SCHEMA collect; +ALTER TABLE IF EXISTS public.server_config SET SCHEMA collect; +ALTER TABLE IF EXISTS public.database_config SET SCHEMA collect; +ALTER TABLE IF EXISTS public.database_states SET SCHEMA collect; +ALTER TABLE IF EXISTS public.trace_flags SET SCHEMA collect; +ALTER TABLE IF EXISTS public.database_scoped_config SET SCHEMA collect; +ALTER TABLE IF EXISTS public.query_store_health SET SCHEMA collect; +ALTER TABLE IF EXISTS public.session_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.session_summary_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.waiting_tasks SET SCHEMA collect; +ALTER TABLE IF EXISTS public.procedure_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.running_jobs SET SCHEMA collect; +ALTER TABLE IF EXISTS public.perfmon_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.dmv_blocking_snapshots SET SCHEMA collect; +ALTER TABLE IF EXISTS public.database_size_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.index_object_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.query_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.query_snapshots SET SCHEMA collect; +ALTER TABLE IF EXISTS public.query_store_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.deadlocks SET SCHEMA collect; +ALTER TABLE IF EXISTS public.blocked_process_reports SET SCHEMA collect; +ALTER TABLE IF EXISTS public.attention_events SET SCHEMA collect; +ALTER TABLE IF EXISTS public.long_query_completions SET SCHEMA collect; +ALTER TABLE IF EXISTS public.system_health_events SET SCHEMA collect; +ALTER TABLE IF EXISTS public.default_trace_events SET SCHEMA collect; +ALTER TABLE IF EXISTS public.job_history SET SCHEMA collect; +ALTER TABLE IF EXISTS public.agent_status SET SCHEMA collect; +ALTER TABLE IF EXISTS public.ag_replica_states SET SCHEMA collect; +ALTER TABLE IF EXISTS public.ag_database_replica_states SET SCHEMA collect; +ALTER TABLE IF EXISTS public.plan_correction SET SCHEMA collect; +ALTER TABLE IF EXISTS public.query_store_forced_plans SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pvs_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_wait_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_statement_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_wraparound_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_server_config SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_deadlocks SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_log_events SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_xmin_horizon SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_replication_slot_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_autovacuum_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_io_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_blocking_edges SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_database_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_index_usage_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_table_bloat_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_session_states SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_plan_capture_readiness SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_write_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_extension_availability SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_lock_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_wait_sampling SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_kernel_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_predicate_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_plan_capture SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_column_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_replication_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_buffer_usage SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_index_bloat SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_cpu_utilization SET SCHEMA collect; +ALTER TABLE IF EXISTS public.pg_database_size_stats SET SCHEMA collect; +ALTER TABLE IF EXISTS public.servers SET SCHEMA collect; +ALTER TABLE IF EXISTS public.collection_log SET SCHEMA collect; +ALTER TABLE IF EXISTS public.analysis_findings SET SCHEMA collect; +ALTER TABLE IF EXISTS public.darling_schema_version SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_wait_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_query_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_query_store_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_cpu_utilization_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_memory_grant_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_memory_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_perfmon_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_session_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_file_io_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_blocked_process_reports SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_deadlocks SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_dmv_blocking_snapshots SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_index_object_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_database_size_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_tempdb_stats SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_query_snapshots SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_database_config SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_running_jobs SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_server_config SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_database_scoped_config SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_trace_flags SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_collection_log SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_memory_clerks SET SCHEMA collect; +ALTER VIEW IF EXISTS public.v_memory_pressure_events SET SCHEMA collect; + +/* config: the operator-writable coordination + analysis-mute tables */ +ALTER TABLE IF EXISTS public.config_alert_log SET SCHEMA config; +ALTER TABLE IF EXISTS public.config_edge_trigger_watermarks SET SCHEMA config; +ALTER TABLE IF EXISTS public.config_mute_rules SET SCHEMA config; +ALTER TABLE IF EXISTS public.analysis_muted SET SCHEMA config; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (8, 'schema-split-collect-config', now()::timestamp); +-- ===BATCH=== V9 server-inventory-cost-fields + +ALTER TABLE server_properties ADD COLUMN IF NOT EXISTS sqlserver_start_time timestamp; +ALTER TABLE server_properties ADD COLUMN IF NOT EXISTS host_os_version text; +ALTER TABLE server_properties ADD COLUMN IF NOT EXISTS ag_replica_role text; +ALTER TABLE servers ADD COLUMN IF NOT EXISTS monthly_cost_usd numeric; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (9, 'server-inventory-cost-fields', now()::timestamp); +-- ===BATCH=== V10 latch-spinlock-collectors +/* V10: latch_stats + spinlock_stats collectors (Dashboard->Darling parity, #1262). + Generated from the collector definitions so the tables match the fresh V1 shape. */ + +CREATE TABLE IF NOT EXISTS latch_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + latch_class text, + waiting_requests_count bigint, + wait_time_ms bigint, + max_wait_time_ms bigint, + delta_waiting_requests_count bigint, + delta_wait_time_ms bigint, + delta_max_wait_time_ms bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_latch_stats_time ON latch_stats(server_id, collection_time); +CREATE OR REPLACE VIEW v_latch_stats AS SELECT * FROM latch_stats; + +CREATE TABLE IF NOT EXISTS spinlock_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + spinlock_name text, + collisions bigint, + spins bigint, + spins_per_collision double precision, + sleep_time bigint, + backoffs bigint, + delta_collisions bigint, + delta_spins bigint, + delta_sleep_time bigint, + delta_backoffs bigint, + sample_interval_seconds integer +); +CREATE INDEX IF NOT EXISTS idx_spinlock_stats_time ON spinlock_stats(server_id, collection_time); +CREATE OR REPLACE VIEW v_spinlock_stats AS SELECT * FROM spinlock_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (10, 'latch-spinlock-collectors', now()::timestamp); +-- ===BATCH=== V11 cpu-scheduler-plan-cache-collectors +/* V11: cpu_scheduler_stats + plan_cache_stats collectors (Dashboard->Darling parity, #1262). + Generated from the collector definitions so the tables match the fresh V1 shape. */ + +CREATE TABLE IF NOT EXISTS cpu_scheduler_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + max_workers_count integer, + scheduler_count integer, + cpu_count integer, + total_runnable_tasks_count integer, + total_work_queue_count bigint, + total_current_workers_count integer, + avg_runnable_tasks_count numeric(38,2), + total_active_request_count integer, + total_queued_request_count integer, + total_blocked_task_count integer, + total_active_parallel_thread_count bigint, + runnable_request_count integer, + total_request_count integer, + runnable_percent numeric(38,2), + worker_thread_exhaustion_warning boolean, + runnable_tasks_warning boolean, + blocked_tasks_warning boolean, + queued_requests_warning boolean, + total_physical_memory_kb bigint, + available_physical_memory_kb bigint, + system_memory_state_desc text, + physical_memory_pressure_warning boolean, + total_node_count integer, + nodes_online_count integer, + offline_cpu_count integer, + offline_cpu_warning boolean +); +CREATE INDEX IF NOT EXISTS idx_cpu_scheduler_stats_time ON cpu_scheduler_stats(server_id, collection_time); +CREATE OR REPLACE VIEW v_cpu_scheduler_stats AS SELECT * FROM cpu_scheduler_stats; + +CREATE TABLE IF NOT EXISTS plan_cache_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + cacheobjtype text, + objtype text, + total_plans integer, + total_size_mb integer, + single_use_plans integer, + single_use_size_mb integer, + multi_use_plans integer, + multi_use_size_mb integer, + avg_use_count numeric(38,2), + avg_size_kb integer, + oldest_plan_create_time timestamp +); +CREATE INDEX IF NOT EXISTS idx_plan_cache_stats_time ON plan_cache_stats(server_id, collection_time); +CREATE OR REPLACE VIEW v_plan_cache_stats AS SELECT * FROM plan_cache_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (11, 'cpu-scheduler-plan-cache-collectors', now()::timestamp); +-- ===BATCH=== V12 session-summary-collector +/* V12: session_summary_stats collector (Dashboard->Darling connection-leak / idle parity, #1262). + Generated from the collector definition so the table matches the fresh V1 shape. */ + +CREATE TABLE IF NOT EXISTS session_summary_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + total_sessions integer, + running_sessions integer, + sleeping_sessions integer, + background_sessions integer, + dormant_sessions integer, + idle_sessions_over_30min integer, + sessions_waiting_for_memory integer, + databases_with_connections integer, + top_application_name text, + top_application_connections integer, + top_host_name text, + top_host_connections integer +); +CREATE INDEX IF NOT EXISTS idx_session_summary_stats_time ON session_summary_stats(server_id, collection_time); +CREATE OR REPLACE VIEW v_session_summary_stats AS SELECT * FROM session_summary_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (12, 'session-summary-collector', now()::timestamp); +-- ===BATCH=== V13 system-health-events-collector +/* V13: system_health_events collector (Dashboard->Darling health-parser capture parity, #1262). + Generated from the collector definition so the table matches the fresh V1 shape. */ + +CREATE TABLE IF NOT EXISTS system_health_events ( + system_health_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_type text, + event_xml text +); +CREATE INDEX IF NOT EXISTS idx_system_health_events_time ON system_health_events(server_id, collection_time); +CREATE OR REPLACE VIEW v_system_health_events AS SELECT * FROM system_health_events; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (13, 'system-health-events-collector', now()::timestamp); +-- ===BATCH=== V14 refresh-passthrough-views +/* V14: refresh every v_* passthrough view's pinned SELECT * column list (#1262). + Postgres freezes SELECT * at CREATE, so an upgraded store's views omit columns + ADDed later (V7 plan columns, V9 inventory); CREATE OR REPLACE re-expands them. + Append-only ADD COLUMNs => the refresh only adds columns at the end (always legal). */ + +CREATE OR REPLACE VIEW v_wait_stats AS SELECT * FROM wait_stats; +CREATE OR REPLACE VIEW v_query_store_stats AS SELECT * FROM query_store_stats; +CREATE OR REPLACE VIEW v_cpu_utilization_stats AS SELECT * FROM cpu_utilization_stats; +CREATE OR REPLACE VIEW v_memory_grant_stats AS SELECT * FROM memory_grant_stats; +CREATE OR REPLACE VIEW v_memory_stats AS SELECT * FROM memory_stats; +CREATE OR REPLACE VIEW v_perfmon_stats AS SELECT * FROM perfmon_stats; +CREATE OR REPLACE VIEW v_session_stats AS SELECT * FROM session_stats; +CREATE OR REPLACE VIEW v_file_io_stats AS SELECT * FROM file_io_stats; +CREATE OR REPLACE VIEW v_blocked_process_reports AS SELECT * FROM blocked_process_reports; +CREATE OR REPLACE VIEW v_deadlocks AS SELECT * FROM deadlocks; +CREATE OR REPLACE VIEW v_dmv_blocking_snapshots AS SELECT * FROM dmv_blocking_snapshots; +CREATE OR REPLACE VIEW v_index_object_stats AS SELECT * FROM index_object_stats; +CREATE OR REPLACE VIEW v_database_size_stats AS SELECT * FROM database_size_stats; +CREATE OR REPLACE VIEW v_tempdb_stats AS SELECT * FROM tempdb_stats; +CREATE OR REPLACE VIEW v_query_snapshots AS SELECT * FROM query_snapshots; +CREATE OR REPLACE VIEW v_database_config AS SELECT * FROM database_config; +CREATE OR REPLACE VIEW v_running_jobs AS SELECT * FROM running_jobs; +CREATE OR REPLACE VIEW v_server_config AS SELECT * FROM server_config; +CREATE OR REPLACE VIEW v_database_scoped_config AS SELECT * FROM database_scoped_config; +CREATE OR REPLACE VIEW v_trace_flags AS SELECT * FROM trace_flags; +CREATE OR REPLACE VIEW v_collection_log AS SELECT * FROM collection_log; +CREATE OR REPLACE VIEW v_memory_clerks AS SELECT * FROM memory_clerks; +CREATE OR REPLACE VIEW v_memory_pressure_events AS SELECT * FROM memory_pressure_events; +CREATE OR REPLACE VIEW v_latch_stats AS SELECT * FROM latch_stats; +CREATE OR REPLACE VIEW v_spinlock_stats AS SELECT * FROM spinlock_stats; +CREATE OR REPLACE VIEW v_cpu_scheduler_stats AS SELECT * FROM cpu_scheduler_stats; +CREATE OR REPLACE VIEW v_plan_cache_stats AS SELECT * FROM plan_cache_stats; +CREATE OR REPLACE VIEW v_session_summary_stats AS SELECT * FROM session_summary_stats; +CREATE OR REPLACE VIEW v_system_health_events AS SELECT * FROM system_health_events; +CREATE OR REPLACE VIEW v_pvs_stats AS SELECT * FROM pvs_stats; +CREATE OR REPLACE VIEW v_query_store_health AS SELECT * FROM query_store_health; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (14, 'refresh-passthrough-views', now()::timestamp); +-- ===BATCH=== V15 index-metadata-columns + +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS key_columns text; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS included_columns text; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS filter_definition text; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_unique_constraint boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_foreign_key boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_foreign_key_reference boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_disabled boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS data_compression_desc text; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS optimize_for_sequential_key boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS fill_factor smallint; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_padded boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS allow_page_locks boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS allow_row_locks boolean; +ALTER TABLE index_object_stats ADD COLUMN IF NOT EXISTS is_indexed_view boolean; + +CREATE OR REPLACE VIEW v_index_object_stats AS SELECT * FROM index_object_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (15, 'index-metadata-columns', now()::timestamp); +-- ===BATCH=== V16 server-utc-offset + +ALTER TABLE server_properties ADD COLUMN IF NOT EXISTS utc_offset_minutes integer; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (16, 'server-utc-offset', now()::timestamp); +-- ===BATCH=== V17 config-control-plane + +/* V17: store<->service control plane (Stage 1). EVERY object is schema-qualified config.* — + the migrate session's search_path resolves bare names to collect (wrong schema/ACL). */ + +/* --- A. Config plane: the Viewer writes desired state, the service reads + honors it. --- */ + +/* 1. config_monitored_servers — the desired-state twin of the collect.servers observed registry. + server_id is THIS ROW'S identity and this table owns it: the service reads it here rather than + recomputing it, so a stored id keeps working when the fields below no longer produce it (#2218). + It is minted from the storage identity host[:database][:RO] — the same value the collectors + stamp, which is why it JOINs collected data and why no existing store needs migrating — but that + is now the ALLOCATION rule, not a definition anything re-derives. is_enabled drives collection; + the connection fields reconstruct a MonitoredServer for the service's connect path. */ +CREATE TABLE IF NOT EXISTS config.config_monitored_servers ( + server_id integer NOT NULL PRIMARY KEY, + name text NOT NULL, + host text NOT NULL, + database text, + auth text NOT NULL DEFAULT 'integrated', + username text, + encrypted_password text, + encrypt_mode text NOT NULL DEFAULT 'Mandatory', + trust_server_certificate boolean NOT NULL DEFAULT FALSE, + read_only_intent boolean NOT NULL DEFAULT FALSE, + multi_subnet_failover boolean NOT NULL DEFAULT FALSE, + excluded_databases text[] NOT NULL DEFAULT '{}'::text[], + monthly_cost_usd numeric NOT NULL DEFAULT 0, + capture_plans boolean, + is_enabled boolean NOT NULL DEFAULT TRUE, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + modified_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC') +); + +/* 2. config_alert_settings — single row (id=1), one column per AlertsConfig field + the analysis + cadence knobs (analysis_enabled / interval / notifications_enabled / notify_severity). */ +CREATE TABLE IF NOT EXISTS config.config_alert_settings ( + id smallint NOT NULL PRIMARY KEY DEFAULT 1 CHECK (id = 1), + enabled boolean NOT NULL DEFAULT TRUE, + cpu_enabled boolean NOT NULL DEFAULT TRUE, + cpu_threshold_percent integer NOT NULL DEFAULT 80, + cpu_mode text NOT NULL DEFAULT 'total', + blocking_enabled boolean NOT NULL DEFAULT TRUE, + blocking_count_threshold integer NOT NULL DEFAULT 1, + deadlock_enabled boolean NOT NULL DEFAULT TRUE, + deadlock_count_threshold integer NOT NULL DEFAULT 1, + poison_wait_enabled boolean NOT NULL DEFAULT TRUE, + poison_wait_threshold_ms integer NOT NULL DEFAULT 500, + long_running_query_enabled boolean NOT NULL DEFAULT TRUE, + long_running_query_threshold_minutes integer NOT NULL DEFAULT 30, + tempdb_space_enabled boolean NOT NULL DEFAULT TRUE, + tempdb_space_threshold_percent integer NOT NULL DEFAULT 80, + low_disk_enabled boolean NOT NULL DEFAULT TRUE, + low_disk_threshold_percent integer NOT NULL DEFAULT 10, + low_disk_threshold_gb integer NOT NULL DEFAULT 5, + long_running_job_enabled boolean NOT NULL DEFAULT TRUE, + long_running_job_multiplier integer NOT NULL DEFAULT 3, + failed_job_enabled boolean NOT NULL DEFAULT TRUE, + failed_job_lookback_minutes integer NOT NULL DEFAULT 60, + cooldown_minutes integer NOT NULL DEFAULT 5, + excluded_databases text[] NOT NULL DEFAULT '{}'::text[], + analysis_enabled boolean NOT NULL DEFAULT TRUE, + analysis_interval_minutes integer NOT NULL DEFAULT 30, + analysis_notifications_enabled boolean NOT NULL DEFAULT TRUE, + analysis_notify_severity double precision NOT NULL DEFAULT 1.5, + modified_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC') +); + +/* 3. config_notification — single row: SMTP + webhook delivery. Non-secret fields plus the SMTP + DPAPI blob (smtp_encrypted_password); webhook URLs/proxies carry as darling.json holds them. */ +CREATE TABLE IF NOT EXISTS config.config_notification ( + id smallint NOT NULL PRIMARY KEY DEFAULT 1 CHECK (id = 1), + smtp_host text NOT NULL DEFAULT '', + smtp_port integer NOT NULL DEFAULT 587, + smtp_use_ssl boolean NOT NULL DEFAULT TRUE, + smtp_username text, + smtp_encrypted_password text, + smtp_from_address text NOT NULL DEFAULT '', + smtp_recipients text NOT NULL DEFAULT '', + email_cooldown_minutes integer NOT NULL DEFAULT 15, + teams_url text NOT NULL DEFAULT '', + teams_proxy text NOT NULL DEFAULT '', + slack_url text NOT NULL DEFAULT '', + slack_proxy text NOT NULL DEFAULT '', + modified_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC') +); + +/* 4. config_collector_schedules — SPARSE per-collector overrides layered on CollectorScheduleDefaults. + Absent row / NULL column = code default; server_id NULL = fleet-wide. A PRIMARY KEY cannot span a + nullable server_id, so two partial-unique indexes enforce one fleet-wide row + one per-server row + per collector. */ +CREATE TABLE IF NOT EXISTS config.config_collector_schedules ( + server_id integer, + collector_name text NOT NULL, + frequency_minutes integer CHECK (frequency_minutes >= 0), + retention_days integer CHECK (retention_days >= 1), + enabled boolean NOT NULL DEFAULT TRUE +); +CREATE UNIQUE INDEX IF NOT EXISTS ux_config_collector_schedules_fleet + ON config.config_collector_schedules (collector_name) WHERE server_id IS NULL; +CREATE UNIQUE INDEX IF NOT EXISTS ux_config_collector_schedules_server + ON config.config_collector_schedules (server_id, collector_name) WHERE server_id IS NOT NULL; + +/* 5. config_service — single row: the service-wide flags + the config_version reload beacon. */ +CREATE TABLE IF NOT EXISTS config.config_service ( + id smallint NOT NULL PRIMARY KEY DEFAULT 1 CHECK (id = 1), + paused boolean NOT NULL DEFAULT FALSE, + capture_plans boolean NOT NULL DEFAULT TRUE, + mcp_enabled boolean NOT NULL DEFAULT FALSE, + mcp_port integer NOT NULL DEFAULT 5152, + config_version bigint NOT NULL DEFAULT 0, + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + updated_by text +); + +/* --- B. Command plane: the Viewer enqueues, the service (Stage 2) claims/executes/reports. --- */ + +/* 6. config_command — the imperative queue. GENERATED ALWAYS AS IDENTITY (a natural queue key that + needs no sequence USAGE grant for admin INSERTs, unlike serial). */ +CREATE TABLE IF NOT EXISTS config.config_command ( + command_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + requested_by text, + command_type text NOT NULL, + target_server_id integer, + args_json jsonb, + status text NOT NULL DEFAULT 'pending', + claimed_at timestamp, + completed_at timestamp, + result_status text, + result_json jsonb, + service_instance text +); +CREATE INDEX IF NOT EXISTS idx_config_command_status ON config.config_command (status); + +/* --- C. The config_version reload beacon (bump triggers). --- */ + +/* Statement-level bump on the four desired-state tables: any write increments the beacon so the + Viewer can never forget to signal. Targets config_service by qualified name (SECURITY INVOKER — + both writers, the owner during seed and admin via the Viewer, hold UPDATE on config_service). */ +CREATE OR REPLACE FUNCTION config.config_bump_version() RETURNS trigger +LANGUAGE plpgsql AS $bump$ +BEGIN + UPDATE config.config_service + SET config_version = config_version + 1, + updated_at = (now() AT TIME ZONE 'UTC') + WHERE id = 1; + RETURN NULL; +END; +$bump$; + +/* Direct writes to config_service (pause/capture/mcp) self-bump the beacon without recursion: the + BEFORE-UPDATE trigger increments NEW.config_version only when the writer did not already change it + (so the config_bump_version UPDATE above, which sets config_version explicitly, is not doubled). */ +CREATE OR REPLACE FUNCTION config.config_service_bump() RETURNS trigger +LANGUAGE plpgsql AS $svc$ +BEGIN + IF NEW.config_version = OLD.config_version THEN + NEW.config_version := OLD.config_version + 1; + END IF; + NEW.updated_at := (now() AT TIME ZONE 'UTC'); + RETURN NEW; +END; +$svc$; + +DROP TRIGGER IF EXISTS trg_bump_monitored_servers ON config.config_monitored_servers; +CREATE TRIGGER trg_bump_monitored_servers + AFTER INSERT OR UPDATE OR DELETE ON config.config_monitored_servers + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +DROP TRIGGER IF EXISTS trg_bump_alert_settings ON config.config_alert_settings; +CREATE TRIGGER trg_bump_alert_settings + AFTER INSERT OR UPDATE OR DELETE ON config.config_alert_settings + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +DROP TRIGGER IF EXISTS trg_bump_notification ON config.config_notification; +CREATE TRIGGER trg_bump_notification + AFTER INSERT OR UPDATE OR DELETE ON config.config_notification + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +DROP TRIGGER IF EXISTS trg_bump_collector_schedules ON config.config_collector_schedules; +CREATE TRIGGER trg_bump_collector_schedules + AFTER INSERT OR UPDATE OR DELETE ON config.config_collector_schedules + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +DROP TRIGGER IF EXISTS trg_service_self_bump ON config.config_service; +CREATE TRIGGER trg_service_self_bump + BEFORE UPDATE ON config.config_service + FOR EACH ROW EXECUTE FUNCTION config.config_service_bump(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (17, 'config-control-plane', now()::timestamp); +-- ===BATCH=== V18 alert-delivery-mode + +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS delivery_mode text NOT NULL DEFAULT 'Summary'; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS per_event_max integer NOT NULL DEFAULT 5; +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS alert_delivery_mode_override text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (18, 'alert-delivery-mode', now()::timestamp); +-- ===BATCH=== V19 analysis-state-marker + +CREATE TABLE IF NOT EXISTS collect.analysis_state ( + server_id integer NOT NULL PRIMARY KEY, + insufficient_data boolean NOT NULL DEFAULT FALSE, + message text, + analysis_time timestamp NOT NULL +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (19, 'analysis-state-marker', now()::timestamp); +-- ===BATCH=== V20 alert-tuning-knobs + +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_max_results integer NOT NULL DEFAULT 5; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_exclude_sp_server_diagnostics boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_exclude_wait_for boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_exclude_backups boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_exclude_misc_waits boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS long_running_query_exclude_cdc boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings ADD COLUMN IF NOT EXISTS notify_connection_changes boolean NOT NULL DEFAULT TRUE; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (20, 'alert-tuning-knobs', now()::timestamp); +-- ===BATCH=== V21 default-trace-events-collector + +CREATE TABLE IF NOT EXISTS collect.default_trace_events ( + default_trace_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_name text, + event_class integer, + spid integer, + database_name text, + database_id integer, + login_name text, + host_name text, + application_name text, + object_name text, + filename text, + integer_data bigint, + integer_data_2 bigint, + text_data text, + session_login_name text, + error_number integer, + severity integer, + state integer, + event_sequence bigint, + duration_us bigint, + end_time timestamp +); + +CREATE INDEX IF NOT EXISTS idx_default_trace_events_time ON collect.default_trace_events(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (21, 'default-trace-events-collector', now()::timestamp); +-- ===BATCH=== V22 index-object-stats-latest-index + +CREATE INDEX IF NOT EXISTS idx_index_object_stats_latest ON collect.index_object_stats (server_id, database_id, object_id, index_id, collection_time DESC); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (22, 'index-object-stats-latest-index', now()::timestamp); +-- ===BATCH=== V23 collection-log-hypertable + +/* V23: best-effort UPGRADE fast-path that converts collect.collection_log to a TimescaleDB hypertable + compresses + it, mirroring the collector hypertables. GUARDED on the extension (plain PostgreSQL skips it, keeping the table a + heap with batched-DELETE retention) and wrapped in EXCEPTION WHEN OTHERS so it can NEVER abort the startup-critical + migration. The AUTHORITATIVE conversion is TimescaleSupport.EnsureCollectionLogHypertableAsync at runtime (after + CREATE EXTENSION), which is the proven-live path and self-heals a fresh store this guard skipped. collection_log is + NOT in the collector catalog, so the runtime catalog loops never touch it. */ +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'timescaledb') THEN + PERFORM create_hypertable('collect.collection_log', by_range('collection_time', INTERVAL '1 days'), if_not_exists => true, migrate_data => true); + ALTER TABLE collect.collection_log SET (timescaledb.compress, timescaledb.compress_segmentby = 'server_id'); + PERFORM add_compression_policy('collect.collection_log', compress_after => INTERVAL '1 days', if_not_exists => true); + END IF; +EXCEPTION WHEN OTHERS THEN + RAISE WARNING 'V23: deferred collection_log hypertable conversion to the runtime path (%): %', SQLSTATE, SQLERRM; +END +$$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (23, 'collection-log-hypertable', now()::timestamp); +-- ===BATCH=== V24 job-history-collector + +CREATE TABLE IF NOT EXISTS collect.job_history ( + job_history_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + instance_id bigint, + job_id text, + job_name text, + job_enabled boolean, + category_name text, + step_id integer, + step_name text, + run_status integer, + run_status_desc text, + run_datetime timestamp, + run_duration_seconds bigint, + retries_attempted integer, + message text +); + +CREATE INDEX IF NOT EXISTS idx_job_history_time ON collect.job_history(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (24, 'job-history-collector', now()::timestamp); +-- ===BATCH=== V25 agent-status-collector + +CREATE TABLE IF NOT EXISTS collect.agent_status ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + agent_running boolean, + agent_status_desc text, + agent_startup_desc text, + next_scheduled_run timestamp +); + +CREATE INDEX IF NOT EXISTS idx_agent_status_time ON collect.agent_status(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (25, 'agent-status-collector', now()::timestamp); +-- ===BATCH=== V26 generic-webhook-channel + +ALTER TABLE config.config_notification ADD COLUMN IF NOT EXISTS generic_url text NOT NULL DEFAULT ''; +ALTER TABLE config.config_notification ADD COLUMN IF NOT EXISTS generic_headers text NOT NULL DEFAULT ''; +ALTER TABLE config.config_notification ADD COLUMN IF NOT EXISTS generic_body_template text NOT NULL DEFAULT ''; +ALTER TABLE config.config_notification ADD COLUMN IF NOT EXISTS generic_proxy text NOT NULL DEFAULT ''; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (26, 'generic-webhook-channel', now()::timestamp); +-- ===BATCH=== V27 deadlocks-database-name + +ALTER TABLE deadlocks ADD COLUMN IF NOT EXISTS database_name text; +CREATE OR REPLACE VIEW v_deadlocks AS SELECT * FROM deadlocks; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (27, 'deadlocks-database-name', now()::timestamp); +-- ===BATCH=== V28 query-store-replica-role + +ALTER TABLE query_store_stats ADD COLUMN IF NOT EXISTS replica_role text; +CREATE OR REPLACE VIEW v_query_store_stats AS SELECT * FROM query_store_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (28, 'query-store-replica-role', now()::timestamp); +-- ===BATCH=== V29 long-query-completions-collector + +CREATE TABLE IF NOT EXISTS collect.long_query_completions ( + long_query_completion_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_type text, + database_id integer, + database_name text, + session_id integer, + client_app_name text, + client_pid integer, + nt_username text, + server_principal_name text, + query_hash text, + event_sequence bigint, + duration_microseconds bigint, + cpu_time_microseconds bigint, + physical_reads bigint, + logical_reads bigint, + writes bigint, + row_count bigint, + result text, + statement_text text, + object_name text +); + +CREATE INDEX IF NOT EXISTS idx_long_query_completions_time ON collect.long_query_completions(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (29, 'long-query-completions-collector', now()::timestamp); +-- ===BATCH=== V30 web-dashboard-config + +ALTER TABLE config.config_service ADD COLUMN IF NOT EXISTS web_enabled boolean NOT NULL DEFAULT FALSE; +ALTER TABLE config.config_service ADD COLUMN IF NOT EXISTS web_port integer NOT NULL DEFAULT 5153; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (30, 'web-dashboard-config', now()::timestamp); +-- ===BATCH=== V31 custom-views-table + +CREATE TABLE IF NOT EXISTS config.custom_views ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name text NOT NULL UNIQUE, + definition jsonb NOT NULL, + description text, + version integer NOT NULL DEFAULT 1, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + updated_by text +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (31, 'custom-views-table', now()::timestamp); +-- ===BATCH=== V32 server-tags + +CREATE TABLE IF NOT EXISTS config.server_tags ( + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name text NOT NULL, + parent_id integer REFERENCES config.server_tags(id) ON DELETE CASCADE, + sort_order integer NOT NULL DEFAULT 0, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC') +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_server_tags_parent_name + ON config.server_tags (COALESCE(parent_id, 0), lower(name)); + +CREATE TABLE IF NOT EXISTS config.server_tag_map ( + server_id integer NOT NULL, + tag_id integer NOT NULL REFERENCES config.server_tags(id) ON DELETE CASCADE, + PRIMARY KEY (server_id, tag_id) +); + +CREATE INDEX IF NOT EXISTS idx_server_tag_map_tag + ON config.server_tag_map (tag_id); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (32, 'server-tags', now()::timestamp); +-- ===BATCH=== V33 connection-alert-refire + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS notify_connection_down_at_startup boolean NOT NULL DEFAULT false, + ADD COLUMN IF NOT EXISTS connection_refire_minutes integer NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (33, 'connection-alert-refire', now()::timestamp); +-- ===BATCH=== V34 availability-group-collectors + +CREATE TABLE IF NOT EXISTS collect.ag_replica_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + ag_name text, + replica_server_name text, + role_desc text, + operational_state_desc text, + connected_state_desc text, + recovery_health_desc text, + synchronization_health_desc text, + availability_mode_desc text, + failover_mode_desc text, + endpoint_url text +); + +CREATE INDEX IF NOT EXISTS idx_ag_replica_states_time ON collect.ag_replica_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS collect.ag_database_replica_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + ag_name text, + database_name text, + replica_server_name text, + is_local boolean, + synchronization_state_desc text, + last_hardened_lsn text, + last_commit_lsn text, + log_send_queue_size bigint, + redo_queue_size bigint, + log_send_rate bigint, + redo_rate bigint, + is_suspended boolean, + suspend_reason_desc text, + availability_mode_desc text, + secondary_lag_seconds bigint +); + +CREATE INDEX IF NOT EXISTS idx_ag_database_replica_states_time ON collect.ag_database_replica_states(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (34, 'availability-group-collectors', now()::timestamp); +-- ===BATCH=== V35 availability-group-alerts + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS notify_ag_health boolean NOT NULL DEFAULT true, + ADD COLUMN IF NOT EXISTS ag_lag_alert_seconds integer NOT NULL DEFAULT 300, + ADD COLUMN IF NOT EXISTS ag_redo_queue_alert_kb bigint NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (35, 'availability-group-alerts', now()::timestamp); +-- ===BATCH=== V36 ag-latency-columns + +ALTER TABLE collect.ag_database_replica_states + ADD COLUMN IF NOT EXISTS last_commit_time timestamp, + ADD COLUMN IF NOT EXISTS last_hardened_time timestamp, + ADD COLUMN IF NOT EXISTS last_redone_time timestamp, + ADD COLUMN IF NOT EXISTS last_received_time timestamp, + ADD COLUMN IF NOT EXISTS est_redo_completion_time_min double precision, + ADD COLUMN IF NOT EXISTS est_send_drain_time_min double precision; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (36, 'ag-latency-columns', now()::timestamp); +-- ===BATCH=== V37 ag-local-replica-and-disconnect-refire + +ALTER TABLE collect.ag_replica_states + ADD COLUMN IF NOT EXISTS is_local boolean; + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS ag_disconnect_refire_minutes integer NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (37, 'ag-local-replica-and-disconnect-refire', now()::timestamp); +-- ===BATCH=== V38 query-payload-dimensions +/* V38: hash-keyed dimension tables for query_stats / procedure_stats payloads (#1767). + query_text/query_plan_xml stored inline per row were 94% of a 250 GB field store; + a measured 1-hour window held 3,166 MB of payload across 23 MB of distinct content. + ZERO-REWRITE: the inline columns stay, new rows leave them NULL, readers coalesce, + and raw retention ages the inline copies out on its own. */ + +CREATE TABLE IF NOT EXISTS query_text_dim ( + digest bytea NOT NULL PRIMARY KEY, + query_text text NOT NULL, + last_seen timestamp NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_query_text_dim_last_seen ON query_text_dim(last_seen); + +CREATE TABLE IF NOT EXISTS query_plan_dim ( + digest bytea NOT NULL PRIMARY KEY, + query_plan_xml text NULL, + query_plan_gz bytea NULL, + last_seen timestamp NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_query_plan_dim_last_seen ON query_plan_dim(last_seen); + +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text_digest bytea; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_digest bytea; +ALTER TABLE procedure_stats ADD COLUMN IF NOT EXISTS query_plan_digest bytea; +/* Pre-adds for the payload-resolving view below: it names every payload column the + collector has today, and a store replaying this rung may predate the ALTER that adds + one of them. Idempotent, so this is a no-op wherever they already exist. */ +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS database_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS creation_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS last_execution_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_clr_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sql_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_generation_num bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS host_object_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_end_offset integer; +ALTER TABLE query_plan_dim ADD COLUMN IF NOT EXISTS query_plan_gz bytea; + +/* v_query_stats resolves each row's payload: the inline column for rows written before + the dimension tables existed, the dimension row for every row written since (#1767). + Column list generated from the collector definition so it can never go stale. */ +CREATE OR REPLACE VIEW v_query_stats AS +SELECT + f.collection_id, + f.collection_time, + f.server_id, + f.server_name, + f.database_name, + f.query_hash, + f.query_plan_hash, + f.creation_time, + f.last_execution_time, + f.execution_count, + f.total_worker_time, + f.total_elapsed_time, + f.total_logical_reads, + f.total_logical_writes, + f.total_physical_reads, + f.total_clr_time, + f.total_rows, + f.total_spills, + f.min_worker_time, + f.max_worker_time, + f.min_elapsed_time, + f.max_elapsed_time, + f.min_physical_reads, + f.max_physical_reads, + f.min_rows, + f.max_rows, + f.min_dop, + f.max_dop, + f.min_grant_kb, + f.max_grant_kb, + f.min_used_grant_kb, + f.max_used_grant_kb, + f.min_ideal_grant_kb, + f.max_ideal_grant_kb, + f.min_reserved_threads, + f.max_reserved_threads, + f.min_used_threads, + f.max_used_threads, + f.min_spills, + f.max_spills, + COALESCE(f.query_text, qtd.query_text) AS query_text, + COALESCE(f.query_plan_xml, qpd.query_plan_xml) AS query_plan_xml, + f.sql_handle, + f.plan_handle, + f.delta_execution_count, + f.delta_worker_time, + f.delta_elapsed_time, + f.delta_logical_reads, + f.delta_logical_writes, + f.delta_physical_reads, + f.delta_rows, + f.delta_spills, + f.plan_generation_num, + f.sample_interval_seconds, + f.host_object_name, + f.query_plan_xml_bytes, + f.statement_start_offset, + f.statement_end_offset, + f.query_text_digest, + f.query_plan_digest, + qpd.query_plan_gz +FROM query_stats AS f +LEFT JOIN query_text_dim AS qtd ON qtd.digest = f.query_text_digest +LEFT JOIN query_plan_dim AS qpd ON qpd.digest = f.query_plan_digest +; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (38, 'query-payload-dimensions', now()::timestamp); +-- ===BATCH=== V39 dim-feeding-fact-floor-indexes + +CREATE INDEX IF NOT EXISTS ix_query_stats_digest_floor + ON query_stats (collection_time) + WHERE query_text_digest IS NOT NULL OR query_plan_digest IS NOT NULL; + +CREATE INDEX IF NOT EXISTS ix_procedure_stats_digest_floor + ON procedure_stats (collection_time) + WHERE query_plan_digest IS NOT NULL; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (39, 'dim-feeding-fact-floor-indexes', now()::timestamp); +-- ===BATCH=== V40 blocking-wait-threshold + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS blocking_wait_seconds_threshold integer NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (40, 'blocking-wait-threshold', now()::timestamp); +-- ===BATCH=== V41 query-store-interval-identity + +ALTER TABLE query_store_stats ADD COLUMN IF NOT EXISTS runtime_stats_interval_id bigint; +ALTER TABLE query_store_stats ADD COLUMN IF NOT EXISTS interval_start_time_utc timestamp; +CREATE OR REPLACE VIEW v_query_store_stats AS SELECT * FROM query_store_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (41, 'query-store-interval-identity', now()::timestamp); +-- ===BATCH=== V42 pagerduty-webhook + +ALTER TABLE config.config_notification + ADD COLUMN IF NOT EXISTS pagerduty_routing_key text NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS pagerduty_use_eu_region boolean NOT NULL DEFAULT FALSE; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (42, 'pagerduty-webhook', now()::timestamp); +-- ===BATCH=== V43 pagerduty-proxy + +ALTER TABLE config.config_notification + ADD COLUMN IF NOT EXISTS pagerduty_proxy text NOT NULL DEFAULT ''; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (43, 'pagerduty-proxy', now()::timestamp); +-- ===BATCH=== V44 collector-state + +CREATE TABLE IF NOT EXISTS collect.collector_state ( + server_id integer NOT NULL, + collector_name text NOT NULL, + state_key text NOT NULL, + state_value text NOT NULL, + updated_at timestamp NOT NULL, + PRIMARY KEY (server_id, collector_name, state_key) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (44, 'collector-state', now()::timestamp); +-- ===BATCH=== V46 plan-correction-collector + +CREATE TABLE IF NOT EXISTS collect.plan_correction ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + force_last_good_plan_desired_state text, + force_last_good_plan_actual_state text, + force_last_good_plan_reason text, + create_index_actual_state text, + drop_index_actual_state text, + recommendation_name text, + recommendation_type text, + recommendation_state text, + recommendation_state_reason text, + recommendation_reason text, + valid_since timestamp, + last_refresh timestamp, + score integer, + query_id bigint, + query_text text, + regressed_plan_id bigint, + last_good_plan_id bigint, + last_good_plan_forcing_type text, + last_good_plan_is_forced boolean, + last_good_plan_force_failure_reason text, + regressed_plan_execution_count bigint, + regressed_plan_cpu_time_average_ms double precision, + regressed_plan_error_count bigint, + last_good_plan_execution_count bigint, + last_good_plan_cpu_time_average_ms double precision, + last_good_plan_error_count bigint, + estimated_gain_seconds double precision, + is_executable_action boolean, + is_revertable_action boolean, + execute_action_initiated_by text, + execute_action_initiated_time timestamp, + execute_action_start_time timestamp, + execute_action_duration_seconds double precision, + revert_action_initiated_by text, + revert_action_initiated_time timestamp, + revert_action_start_time timestamp, + revert_action_duration_seconds double precision, + implementation_script text +); + +CREATE INDEX IF NOT EXISTS idx_plan_correction_time ON collect.plan_correction(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (46, 'plan-correction-collector', now()::timestamp); +-- ===BATCH=== V47 pvs-stats + +CREATE TABLE IF NOT EXISTS collect.pvs_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + database_id integer, + is_accelerated_database_recovery_on boolean, + pvs_filegroup_id smallint, + persistent_version_store_size_mb numeric(19,2), + online_index_version_store_size_mb numeric(19,2), + database_data_size_mb numeric(19,2), + current_aborted_transaction_count bigint, + oldest_active_transaction_id bigint, + oldest_aborted_transaction_id bigint, + min_transaction_timestamp bigint, + online_index_min_transaction_timestamp bigint, + secondary_low_water_mark bigint, + offrow_version_cleaner_start_time timestamp, + offrow_version_cleaner_end_time timestamp, + aborted_version_cleaner_start_time timestamp, + aborted_version_cleaner_end_time timestamp, + pvs_off_row_page_skipped_low_water_mark bigint, + pvs_off_row_page_skipped_transaction_not_cleaned bigint, + pvs_off_row_page_skipped_oldest_active_xdesid bigint, + pvs_off_row_page_skipped_min_useful_xts bigint, + pvs_off_row_page_skipped_oldest_snapshot bigint, + pvs_off_row_page_skipped_oldest_aborted_xdesid bigint +); + +CREATE INDEX IF NOT EXISTS idx_pvs_stats_time ON collect.pvs_stats(server_id, collection_time); + +CREATE OR REPLACE VIEW v_pvs_stats AS SELECT * FROM pvs_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (47, 'pvs-stats', now()::timestamp); +-- ===BATCH=== V48 pvs-pressure-alert + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS pvs_enabled boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS pvs_threshold_percent integer NOT NULL DEFAULT 40; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS pvs_floor_gb integer NOT NULL DEFAULT 1; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (48, 'pvs-pressure-alert', now()::timestamp); +-- ===BATCH=== V49 database-state-alert + +CREATE TABLE IF NOT EXISTS collect.database_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + database_id integer, + state_desc text, + is_in_standby boolean +); + +CREATE INDEX IF NOT EXISTS idx_database_states_time ON collect.database_states(server_id, collection_time); + +CREATE TABLE IF NOT EXISTS config.database_state_expected ( + server_id integer NOT NULL, + database_name text NOT NULL, + expected_state text NOT NULL, + is_user_override boolean NOT NULL DEFAULT false, + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + PRIMARY KEY (server_id, database_name) +); + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS database_state_enabled boolean NOT NULL DEFAULT true; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (49, 'database-state-alert', now()::timestamp); +-- ===BATCH=== V50 server-tag-colour + +ALTER TABLE config.server_tags + ADD COLUMN IF NOT EXISTS colour text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (50, 'server-tag-colour', now()::timestamp); +-- ===BATCH=== V51 query-stats-host-object + +ALTER TABLE query_stats + ADD COLUMN IF NOT EXISTS host_object_name text; +DROP VIEW IF EXISTS v_query_stats; + +ALTER TABLE query_plan_dim + ADD COLUMN IF NOT EXISTS query_plan_gz bytea; +ALTER TABLE query_plan_dim + ALTER COLUMN query_plan_xml DROP NOT NULL; +/* Pre-adds for the payload-resolving view below: it names every payload column the + collector has today, and a store replaying this rung may predate the ALTER that adds + one of them. Idempotent, so this is a no-op wherever they already exist. */ +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS database_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS creation_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS last_execution_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_clr_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sql_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_generation_num bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS host_object_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_end_offset integer; + +/* v_query_stats resolves each row's payload: the inline column for rows written before + the dimension tables existed, the dimension row for every row written since (#1767). + Column list generated from the collector definition so it can never go stale. */ +CREATE OR REPLACE VIEW v_query_stats AS +SELECT + f.collection_id, + f.collection_time, + f.server_id, + f.server_name, + f.database_name, + f.query_hash, + f.query_plan_hash, + f.creation_time, + f.last_execution_time, + f.execution_count, + f.total_worker_time, + f.total_elapsed_time, + f.total_logical_reads, + f.total_logical_writes, + f.total_physical_reads, + f.total_clr_time, + f.total_rows, + f.total_spills, + f.min_worker_time, + f.max_worker_time, + f.min_elapsed_time, + f.max_elapsed_time, + f.min_physical_reads, + f.max_physical_reads, + f.min_rows, + f.max_rows, + f.min_dop, + f.max_dop, + f.min_grant_kb, + f.max_grant_kb, + f.min_used_grant_kb, + f.max_used_grant_kb, + f.min_ideal_grant_kb, + f.max_ideal_grant_kb, + f.min_reserved_threads, + f.max_reserved_threads, + f.min_used_threads, + f.max_used_threads, + f.min_spills, + f.max_spills, + COALESCE(f.query_text, qtd.query_text) AS query_text, + COALESCE(f.query_plan_xml, qpd.query_plan_xml) AS query_plan_xml, + f.sql_handle, + f.plan_handle, + f.delta_execution_count, + f.delta_worker_time, + f.delta_elapsed_time, + f.delta_logical_reads, + f.delta_logical_writes, + f.delta_physical_reads, + f.delta_rows, + f.delta_spills, + f.plan_generation_num, + f.sample_interval_seconds, + f.host_object_name, + f.query_plan_xml_bytes, + f.statement_start_offset, + f.statement_end_offset, + f.query_text_digest, + f.query_plan_digest, + qpd.query_plan_gz +FROM query_stats AS f +LEFT JOIN query_text_dim AS qtd ON qtd.digest = f.query_text_digest +LEFT JOIN query_plan_dim AS qpd ON qpd.digest = f.query_plan_digest +; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (51, 'query-stats-host-object', now()::timestamp); +-- ===BATCH=== V52 finding-drilldown-json + +ALTER TABLE analysis_findings + ADD COLUMN IF NOT EXISTS drill_down_json text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (52, 'finding-drilldown-json', now()::timestamp); +-- ===BATCH=== V53 store-self-metrics + +CREATE TABLE IF NOT EXISTS collect.store_metrics ( + metric_time timestamp NOT NULL, + object_name text NOT NULL, + object_kind text NOT NULL, + total_bytes bigint, + compressed_before_bytes bigint, + compressed_after_bytes bigint, + chunk_count integer, + row_count bigint, + enabled_server_count integer +); + +CREATE INDEX IF NOT EXISTS idx_store_metrics_time ON collect.store_metrics(metric_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (53, 'store-self-metrics', now()::timestamp); +-- ===BATCH=== V54 plan-dim-gzip + +ALTER TABLE query_plan_dim + ADD COLUMN IF NOT EXISTS query_plan_gz bytea; +ALTER TABLE query_plan_dim + ALTER COLUMN query_plan_xml DROP NOT NULL; +/* Pre-adds for the payload-resolving view below: it names every payload column the + collector has today, and a store replaying this rung may predate the ALTER that adds + one of them. Idempotent, so this is a no-op wherever they already exist. */ +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS database_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS creation_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS last_execution_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_clr_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sql_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_generation_num bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS host_object_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_end_offset integer; + +/* v_query_stats resolves each row's payload: the inline column for rows written before + the dimension tables existed, the dimension row for every row written since (#1767). + Column list generated from the collector definition so it can never go stale. */ +CREATE OR REPLACE VIEW v_query_stats AS +SELECT + f.collection_id, + f.collection_time, + f.server_id, + f.server_name, + f.database_name, + f.query_hash, + f.query_plan_hash, + f.creation_time, + f.last_execution_time, + f.execution_count, + f.total_worker_time, + f.total_elapsed_time, + f.total_logical_reads, + f.total_logical_writes, + f.total_physical_reads, + f.total_clr_time, + f.total_rows, + f.total_spills, + f.min_worker_time, + f.max_worker_time, + f.min_elapsed_time, + f.max_elapsed_time, + f.min_physical_reads, + f.max_physical_reads, + f.min_rows, + f.max_rows, + f.min_dop, + f.max_dop, + f.min_grant_kb, + f.max_grant_kb, + f.min_used_grant_kb, + f.max_used_grant_kb, + f.min_ideal_grant_kb, + f.max_ideal_grant_kb, + f.min_reserved_threads, + f.max_reserved_threads, + f.min_used_threads, + f.max_used_threads, + f.min_spills, + f.max_spills, + COALESCE(f.query_text, qtd.query_text) AS query_text, + COALESCE(f.query_plan_xml, qpd.query_plan_xml) AS query_plan_xml, + f.sql_handle, + f.plan_handle, + f.delta_execution_count, + f.delta_worker_time, + f.delta_elapsed_time, + f.delta_logical_reads, + f.delta_logical_writes, + f.delta_physical_reads, + f.delta_rows, + f.delta_spills, + f.plan_generation_num, + f.sample_interval_seconds, + f.host_object_name, + f.query_plan_xml_bytes, + f.statement_start_offset, + f.statement_end_offset, + f.query_text_digest, + f.query_plan_digest, + qpd.query_plan_gz +FROM query_stats AS f +LEFT JOIN query_text_dim AS qtd ON qtd.digest = f.query_text_digest +LEFT JOIN query_plan_dim AS qpd ON qpd.digest = f.query_plan_digest +; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (54, 'plan-dim-gzip', now()::timestamp); +-- ===BATCH=== V55 self-alert-knobs + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS self_disk_free_warn_percent integer NOT NULL DEFAULT 10; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS collection_stale_minutes integer NOT NULL DEFAULT 30; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS collection_failure_threshold integer NOT NULL DEFAULT 10; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS disk_critical_free_percent integer NOT NULL DEFAULT 3; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS disk_critical_free_gb integer NOT NULL DEFAULT 2; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS analysis_notify_cooldown_minutes integer NOT NULL DEFAULT 360; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (55, 'self-alert-knobs', now()::timestamp); +-- ===BATCH=== V56 store-metrics-background-jobs + +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS last_run_duration_ms bigint; +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS schedule_interval_ms bigint; +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS total_runs bigint; +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS total_failures bigint; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (56, 'store-metrics-background-jobs', now()::timestamp); +-- ===BATCH=== V57 store-job-cadence-knob + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS store_job_cadence_warn_percent integer NOT NULL DEFAULT 25; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (57, 'store-job-cadence-knob', now()::timestamp); +-- ===BATCH=== V58 qs-backfill-switch + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS query_store_backfill_enabled boolean NOT NULL DEFAULT TRUE; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (58, 'qs-backfill-switch', now()::timestamp); +-- ===BATCH=== V59 collector-memory-knobs + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS query_store_text_budget_mb integer NOT NULL DEFAULT 64; +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS max_concurrent_sweeps integer NOT NULL DEFAULT 4; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (59, 'collector-memory-knobs', now()::timestamp); +-- ===BATCH=== V60 database-state-edge-memory + +ALTER TABLE config.database_state_expected + ADD COLUMN IF NOT EXISTS last_alerted_state text; +ALTER TABLE config.database_state_expected + ADD COLUMN IF NOT EXISTS last_alerted_at timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (60, 'database-state-edge-memory', now()::timestamp); +-- ===BATCH=== V61 incident-occurrence-counters + +CREATE TABLE IF NOT EXISTS config.incident_occurrences ( + server_id integer NOT NULL, + metric_name text NOT NULL, + dedup_key text NOT NULL, + total_occurrences bigint NOT NULL, + observed_window_count integer NOT NULL, + incident_started_at timestamp NOT NULL, + last_observed_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + PRIMARY KEY (server_id, metric_name, dedup_key) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (61, 'incident-occurrence-counters', now()::timestamp); +-- ===BATCH=== V62 plan-xml-compression-knob + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS plan_xml_compression text NOT NULL DEFAULT 'gzip'; +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'config_service_plan_xml_compression_check' + ) THEN + ALTER TABLE config.config_service + ADD CONSTRAINT config_service_plan_xml_compression_check + CHECK (plan_xml_compression IN ('gzip', 'none')); + END IF; +END $$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (62, 'plan-xml-compression-knob', now()::timestamp); +-- ===BATCH=== V63 pg-wait-stats + +CREATE TABLE IF NOT EXISTS collect.pg_wait_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + wait_type_id integer, + wait_event_id bigint, + wait_type text, + wait_event text, + waits bigint, + wait_time_us bigint, + delta_waits bigint, + delta_wait_time_us bigint, + sample_interval_seconds integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_wait_stats_time + ON collect.pg_wait_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (63, 'pg-wait-stats', now()::timestamp); +-- ===BATCH=== V64 pg-statement-stats + +CREATE TABLE IF NOT EXISTS collect.pg_statement_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + queryid bigint, + database_id bigint, + user_id bigint, + toplevel boolean, + calls bigint, + total_exec_time_ms double precision, + min_exec_time_ms double precision, + max_exec_time_ms double precision, + mean_exec_time_ms double precision, + rows_returned bigint, + shared_blks_hit bigint, + shared_blks_read bigint, + shared_blks_dirtied bigint, + shared_blks_written bigint, + temp_blks_read bigint, + temp_blks_written bigint, + blk_read_time_ms double precision, + blk_write_time_ms double precision, + storage_blks_read bigint, + orcache_blks_hit bigint, + storage_blk_read_time_ms double precision, + orcache_blk_read_time_ms double precision, + wal_records bigint, + wal_fpi bigint, + wal_bytes bigint, + total_exec_peakmem_bytes bigint, + max_exec_peakmem_bytes bigint, + delta_calls bigint, + delta_total_exec_time_ms bigint, + delta_rows bigint, + sample_interval_seconds integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_statement_stats_time + ON collect.pg_statement_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (64, 'pg-statement-stats', now()::timestamp); +-- ===BATCH=== V65 pg-wraparound-stats + +CREATE TABLE IF NOT EXISTS collect.pg_wraparound_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + frozen_xid_age bigint, + min_multixid_age bigint, + autovacuum_freeze_max_age bigint, + autovacuum_multixact_freeze_max_age bigint, + pct_toward_emergency_vacuum double precision, + pct_toward_wraparound double precision, + pct_toward_multixact_emergency double precision, + pct_toward_multixact_wraparound double precision, + xids_remaining bigint, + multixids_remaining bigint, + allows_connections boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_wraparound_stats_time + ON collect.pg_wraparound_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (65, 'pg-wraparound-stats', now()::timestamp); +-- ===BATCH=== V66 pg-xmin-horizon + +CREATE TABLE IF NOT EXISTS collect.pg_xmin_horizon ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + source text, + xmin_age bigint, + holder text, + detail text, + is_winner boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_xmin_horizon_time + ON collect.pg_xmin_horizon(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (66, 'pg-xmin-horizon', now()::timestamp); +-- ===BATCH=== V67 pg-replication-slots + +CREATE TABLE IF NOT EXISTS collect.pg_replication_slot_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + slot_name text, + slot_type text, + plugin text, + database_name text, + is_active boolean, + active_pid bigint, + is_temporary boolean, + two_phase boolean, + wal_status text, + safe_wal_size_bytes bigint, + retained_wal_bytes bigint, + xmin_age bigint, + catalog_xmin_age bigint, + inactive_since timestamp, + invalidation_reason text, + conflicting boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_replication_slot_stats_time + ON collect.pg_replication_slot_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (67, 'pg-replication-slots', now()::timestamp); +-- ===BATCH=== V68 pg-autovacuum-stats + +CREATE TABLE IF NOT EXISTS collect.pg_autovacuum_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + live_tuples bigint, + dead_tuples bigint, + mods_since_analyze bigint, + inserts_since_vacuum bigint, + vacuum_threshold bigint, + insert_vacuum_threshold bigint, + analyze_threshold bigint, + autovacuum_disabled boolean, + total_bytes bigint, + last_vacuum timestamp, + last_autovacuum timestamp, + last_analyze timestamp, + last_autoanalyze timestamp, + vacuum_count bigint, + autovacuum_count bigint, + analyze_count bigint, + autoanalyze_count bigint +); + +CREATE INDEX IF NOT EXISTS idx_pg_autovacuum_stats_time + ON collect.pg_autovacuum_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (68, 'pg-autovacuum-stats', now()::timestamp); +-- ===BATCH=== V69 pg-io-stats + +CREATE TABLE IF NOT EXISTS collect.pg_io_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + backend_type text, + object_type text, + context text, + reads bigint, + read_time_ms double precision, + writes bigint, + write_time_ms double precision, + writebacks bigint, + writeback_time_ms double precision, + extends bigint, + extend_time_ms double precision, + op_bytes bigint, + hits bigint, + evictions bigint, + reuses bigint, + fsyncs bigint, + fsync_time_ms double precision, + stats_reset timestamp, + read_bytes numeric(28,0), + write_bytes numeric(28,0), + extend_bytes numeric(28,0) +); + +CREATE INDEX IF NOT EXISTS idx_pg_io_stats_time + ON collect.pg_io_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (69, 'pg-io-stats', now()::timestamp); +-- ===BATCH=== V70 monitored-server-engine + +ALTER TABLE config.config_monitored_servers + ADD COLUMN IF NOT EXISTS engine text NOT NULL DEFAULT 'sqlserver'; + +ALTER TABLE config.config_monitored_servers + ADD COLUMN IF NOT EXISTS port integer NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (70, 'monitored-server-engine', now()::timestamp); +-- ===BATCH=== V71 pg-blocking-edges + +CREATE TABLE IF NOT EXISTS collect.pg_blocking_edges ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + blocked_backend_id bigint, + blocked_pid integer, + blocking_backend_id bigint, + blocking_pid integer, + database_name text, + blocked_username text, + blocked_application_name text, + blocked_client_addr text, + blocked_state text, + blocked_wait_event_type text, + blocked_wait_event text, + blocked_query text, + blocked_xact_duration_ms bigint, + blocked_query_duration_ms bigint, + blocking_username text, + blocking_application_name text, + blocking_client_addr text, + blocking_state text, + blocking_wait_event_type text, + blocking_wait_event text, + blocking_query text, + blocking_xact_duration_ms bigint, + blocking_query_duration_ms bigint, + blocked_pid_count integer, + blocking_is_idle_in_transaction boolean, + query_text_may_be_truncated boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_blocking_edges_time + ON collect.pg_blocking_edges(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (71, 'pg-blocking-edges', now()::timestamp); +-- ===BATCH=== V72 query-store-plan-map + +CREATE TABLE IF NOT EXISTS collect.query_store_plan_map ( + server_id integer NOT NULL, + database_name text NOT NULL, + plan_id bigint NOT NULL, + digest bytea NOT NULL, + plan_hash text, + last_seen timestamp NOT NULL, + PRIMARY KEY (server_id, database_name, plan_id) +); +CREATE INDEX IF NOT EXISTS idx_query_store_plan_map_last_seen + ON collect.query_store_plan_map(last_seen); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (72, 'query-store-plan-map', now()::timestamp); +-- ===BATCH=== V73 pg-statement-text + +CREATE TABLE IF NOT EXISTS collect.pg_statement_text ( + server_id integer NOT NULL, + queryid bigint NOT NULL, + query_text text NOT NULL, + first_seen timestamp NOT NULL, + last_seen timestamp NOT NULL, + PRIMARY KEY (server_id, queryid) +); +CREATE INDEX IF NOT EXISTS idx_pg_statement_text_last_seen + ON collect.pg_statement_text(last_seen); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (73, 'pg-statement-text', now()::timestamp); +-- ===BATCH=== V74 query-store-text +CREATE TABLE IF NOT EXISTS collect.query_store_text ( + server_id integer NOT NULL, + database_name text NOT NULL, + query_id bigint NOT NULL, + query_sql_text text, + last_seen timestamp NOT NULL, + PRIMARY KEY (server_id, database_name, query_id) +); +CREATE INDEX IF NOT EXISTS idx_query_store_text_last_seen + ON collect.query_store_text(last_seen); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (74, 'query-store-text', now()::timestamp); +-- ===BATCH=== V75 plan-content-retention-knob + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS plan_content_retention_days integer NOT NULL DEFAULT 21; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (75, 'plan-content-retention-knob', now()::timestamp); +-- ===BATCH=== V76 query-store-health + +CREATE TABLE IF NOT EXISTS collect.query_store_health ( + config_id bigint NOT NULL, + capture_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + actual_state text, + desired_state text, + readonly_reason integer, + current_storage_size_mb bigint, + max_storage_size_mb bigint, + size_based_cleanup_mode text, + stale_query_threshold_days bigint, + max_plans_per_query bigint, + interval_length_minutes bigint, + query_capture_mode text, + wait_stats_capture_mode text +); + +CREATE INDEX IF NOT EXISTS idx_query_store_health_time ON collect.query_store_health(server_id, capture_time); + +CREATE OR REPLACE VIEW v_query_store_health AS SELECT * FROM query_store_health; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (76, 'query-store-health', now()::timestamp); +-- ===BATCH=== V77 activity-driven-plan-fetch + +ALTER TABLE collect.query_store_plan_map ALTER COLUMN digest DROP NOT NULL; + +ALTER TABLE collect.query_store_text ADD COLUMN IF NOT EXISTS query_hash text; + +DELETE FROM collector_state WHERE collector_name = 'query_store_plan_xml' AND state_key LIKE 'planwm:%'; +DELETE FROM collector_state WHERE collector_name = 'query_store_text' AND state_key LIKE 'textwm:%'; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (77, 'activity-driven-plan-fetch', now()::timestamp); +-- ===BATCH=== V78 compose-statement-timeout + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS compose_statement_timeout_seconds integer NOT NULL DEFAULT 15; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (78, 'compose-statement-timeout', now()::timestamp); +-- ===BATCH=== V79 file-growth-alert + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS file_growth_enabled boolean NOT NULL DEFAULT false, + ADD COLUMN IF NOT EXISTS file_growth_rise_mb integer NOT NULL DEFAULT 10240, + ADD COLUMN IF NOT EXISTS file_growth_volume_percent integer NOT NULL DEFAULT 60, + ADD COLUMN IF NOT EXISTS file_growth_lookback_minutes integer NOT NULL DEFAULT 60; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (79, 'file-growth-alert', now()::timestamp); +-- ===BATCH=== V80 collection-log-fanout-rollup + +ALTER TABLE collect.collection_log + ADD COLUMN IF NOT EXISTS fanout_item_count integer, + ADD COLUMN IF NOT EXISTS slowest_item text, + ADD COLUMN IF NOT EXISTS slowest_item_ms integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the passthrough every read goes through + would keep serving eleven columns forever — the V14 lesson, and the reason it exists. Appending is the + one alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_collection_log AS SELECT * FROM collect.collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (80, 'collection-log-fanout-rollup', now()::timestamp); +-- ===BATCH=== V81 tempdb-max-size + +ALTER TABLE collect.tempdb_stats + ADD COLUMN IF NOT EXISTS max_size_mb numeric(18,2); + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the V4 passthrough the analysis fact + collector reads would keep serving the twelve columns it had forever — the V14 lesson, restated by V80. + Appending is the one alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN + produces. */ +CREATE OR REPLACE VIEW collect.v_tempdb_stats AS SELECT * FROM collect.tempdb_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (81, 'tempdb-max-size', now()::timestamp); +-- ===BATCH=== V82 server-engine-kind + +ALTER TABLE collect.servers + ADD COLUMN IF NOT EXISTS engine_kind text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (82, 'server-engine-kind', now()::timestamp); +-- ===BATCH=== V83 pg-database-stats + +CREATE TABLE IF NOT EXISTS collect.pg_database_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + xact_commit bigint, + xact_rollback bigint, + blks_read bigint, + blks_hit bigint, + temp_files bigint, + temp_bytes bigint, + deadlocks bigint, + stats_reset timestamp, + numbackends integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_database_stats_time + ON collect.pg_database_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (83, 'pg-database-stats', now()::timestamp); +-- ===BATCH=== V84 pg-index-usage-stats + +CREATE TABLE IF NOT EXISTS collect.pg_index_usage_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + index_name text, + index_scans bigint, + tuples_read bigint, + tuples_fetched bigint, + blocks_read bigint, + blocks_hit bigint, + index_bytes bigint, + table_bytes bigint, + is_unique boolean, + is_primary_key boolean, + is_valid boolean, + is_ready boolean, + is_replica_identity boolean, + is_partial boolean, + is_expression boolean, + supports_constraint boolean, + index_method text, + column_count integer, + index_definition text, + last_scan timestamp, + stats_reset timestamp +); + +CREATE INDEX IF NOT EXISTS idx_pg_index_usage_stats_time + ON collect.pg_index_usage_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (84, 'pg-index-usage-stats', now()::timestamp); +-- ===BATCH=== V85 pg-table-bloat-stats + +CREATE TABLE IF NOT EXISTS collect.pg_table_bloat_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + heap_bytes bigint, + heap_pages bigint, + toast_bytes bigint, + index_bytes bigint, + live_tuples bigint, + dead_tuples bigint, + mods_since_analyze bigint, + last_analyzed timestamp, + estimated_tuple_bytes double precision, + estimated_heap_pages bigint, + fillfactor integer, + bloat_bytes_estimate bigint, + bloat_pct_estimate numeric(5,2), + estimate_unavailable boolean, + alignment_bytes integer, + pgstattuple_available boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_table_bloat_stats_time + ON collect.pg_table_bloat_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (85, 'pg-table-bloat-stats', now()::timestamp); +-- ===BATCH=== V86 pg-session-states + +CREATE TABLE IF NOT EXISTS collect.pg_session_states ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + backend_id bigint, + pid integer, + database_name text, + username text, + application_name text, + client_addr text, + backend_type text, + state text, + wait_event_type text, + wait_event text, + command_tag text, + query_id bigint, + state_duration_ms bigint, + xact_duration_ms bigint, + query_duration_ms bigint, + backend_duration_ms bigint, + xmin_age bigint, + xid_age bigint, + horizon_age bigint, + is_idle_in_transaction boolean, + is_horizon_holder boolean, + state_is_redacted boolean, + total_sessions integer, + active_sessions integer, + idle_in_transaction_sessions integer, + reportable_sessions integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_session_states_time + ON collect.pg_session_states(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (86, 'pg-session-states', now()::timestamp); +-- ===BATCH=== V87 pg-plan-capture-readiness + +CREATE TABLE IF NOT EXISTS collect.pg_plan_capture_readiness ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + facet text, + is_satisfied boolean, + observed text, + detail text +); + +CREATE INDEX IF NOT EXISTS idx_pg_plan_capture_readiness_time + ON collect.pg_plan_capture_readiness(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (87, 'pg-plan-capture-readiness', now()::timestamp); +-- ===BATCH=== V88 pg-write-stats + +CREATE TABLE IF NOT EXISTS collect.pg_write_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + num_timed bigint, + num_requested bigint, + num_done bigint, + restartpoints_timed bigint, + restartpoints_req bigint, + restartpoints_done bigint, + checkpoint_write_time_ms double precision, + checkpoint_sync_time_ms double precision, + buffers_written_checkpoint bigint, + slru_written bigint, + checkpointer_stats_reset timestamp, + buffers_clean bigint, + maxwritten_clean bigint, + buffers_alloc bigint, + buffers_backend bigint, + buffers_backend_fsync bigint, + bgwriter_stats_reset timestamp, + wal_records bigint, + wal_fpi bigint, + wal_bytes numeric(38,0), + wal_buffers_full bigint, + wal_write bigint, + wal_sync bigint, + wal_write_time_ms double precision, + wal_sync_time_ms double precision, + wal_stats_reset timestamp, + postmaster_start_time timestamp +); + +CREATE INDEX IF NOT EXISTS idx_pg_write_stats_time + ON collect.pg_write_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (88, 'pg-write-stats', now()::timestamp); +-- ===BATCH=== V89 pg-extension-availability + +CREATE TABLE IF NOT EXISTS collect.pg_extension_availability ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + extension_name text, + state text, + installed_version text, + default_version text, + is_monitoring_relevant boolean, + comment text +); + +CREATE INDEX IF NOT EXISTS idx_pg_extension_availability_time + ON collect.pg_extension_availability(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (89, 'pg-extension-availability', now()::timestamp); +-- ===BATCH=== V90 pg-lock-stats + +CREATE TABLE IF NOT EXISTS collect.pg_lock_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + lock_type text, + mode text, + granted boolean, + relation_oid bigint, + relation_name text, + backend_count bigint, + oldest_wait_ms double precision +); + +CREATE INDEX IF NOT EXISTS idx_pg_lock_stats_time + ON collect.pg_lock_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (90, 'pg-lock-stats', now()::timestamp); +-- ===BATCH=== V91 pg-column-stats + +CREATE TABLE IF NOT EXISTS collect.pg_column_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + column_name text, + n_distinct double precision, + null_frac double precision, + avg_width integer, + correlation double precision, + top_value_frequency double precision, + common_value_count integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_column_stats_time + ON collect.pg_column_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (91, 'pg-column-stats', now()::timestamp); +-- ===BATCH=== V92 pg-replication-stats + +CREATE TABLE IF NOT EXISTS collect.pg_replication_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + application_name text, + client_addr text, + state text, + sync_state text, + sync_priority integer, + sent_bytes_behind bigint, + write_bytes_behind bigint, + flush_bytes_behind bigint, + replay_bytes_behind bigint, + write_lag_ms double precision, + flush_lag_ms double precision, + replay_lag_ms double precision, + backend_start timestamp +); + +CREATE INDEX IF NOT EXISTS idx_pg_replication_stats_time + ON collect.pg_replication_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (92, 'pg-replication-stats', now()::timestamp); +-- ===BATCH=== V93 pg-buffer-usage + +CREATE TABLE IF NOT EXISTS collect.pg_buffer_usage ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + relation_name text, + relation_kind text, + buffers bigint, + dirty_buffers bigint, + avg_usage_count double precision, + pool_buffers_total bigint, + pool_buffers_used bigint +); + +CREATE INDEX IF NOT EXISTS idx_pg_buffer_usage_time + ON collect.pg_buffer_usage(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (93, 'pg-buffer-usage', now()::timestamp); +-- ===BATCH=== V94 pg-index-bloat + +CREATE TABLE IF NOT EXISTS collect.pg_index_bloat ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + index_name text, + index_bytes bigint, + tree_level integer, + internal_pages bigint, + leaf_pages bigint, + empty_pages bigint, + deleted_pages bigint, + avg_leaf_density double precision, + leaf_fragmentation double precision, + skipped_reason text, + index_pages bigint, + table_rows bigint, + fillfactor integer, + est_tuple_bytes bigint, + est_leaf_pages bigint, + est_bloat_pct double precision, + est_reclaimable_bytes bigint, + pgstattuple_available boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_index_bloat_time + ON collect.pg_index_bloat(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (94, 'pg-index-bloat', now()::timestamp); +-- ===BATCH=== V95 pg-per-database-attribution + +ALTER TABLE collect.pg_column_stats + ADD COLUMN IF NOT EXISTS database_name text; + +ALTER TABLE collect.pg_index_bloat + ADD COLUMN IF NOT EXISTS database_name text; + +ALTER TABLE collect.pg_extension_availability + ADD COLUMN IF NOT EXISTS database_name text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (95, 'pg-per-database-attribution', now()::timestamp); +-- ===BATCH=== V96 pg-wait-sampling + +CREATE TABLE IF NOT EXISTS collect.pg_wait_sampling ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_type text, + event text, + query_id bigint, + sample_count bigint, + profile_period_ms integer, + backend_count integer, + sampled_ms integer +); + +CREATE INDEX IF NOT EXISTS idx_pg_wait_sampling_time + ON collect.pg_wait_sampling(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (96, 'pg-wait-sampling', now()::timestamp); +-- ===BATCH=== V97 pg-kernel-stats + +CREATE TABLE IF NOT EXISTS collect.pg_kernel_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + query_id bigint, + exec_user_time_ms double precision, + exec_system_time_ms double precision, + plan_cpu_time_ms double precision, + exec_read_bytes bigint, + exec_write_bytes bigint, + minor_faults bigint, + major_faults bigint, + stats_since timestamp +); + +CREATE INDEX IF NOT EXISTS idx_pg_kernel_stats_time + ON collect.pg_kernel_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (97, 'pg-kernel-stats', now()::timestamp); +-- ===BATCH=== V98 pg-predicate-stats + +CREATE TABLE IF NOT EXISTS collect.pg_predicate_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + schema_name text, + table_name text, + column_name text, + operator text, + query_id bigint, + sample_count bigint, + rows_evaluated bigint, + rows_filtered bigint, + worst_estimate_error_ratio double precision, + sample_rate double precision +); + +CREATE INDEX IF NOT EXISTS idx_pg_predicate_stats_time + ON collect.pg_predicate_stats(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (98, 'pg-predicate-stats', now()::timestamp); +-- ===BATCH=== V99 pg-plan-capture + +CREATE TABLE IF NOT EXISTS collect.pg_plan_capture ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + query_id bigint, + plan_hash text, + duration_ms double precision, + node_count integer, + top_node_type text, + plan_json text +); + +CREATE INDEX IF NOT EXISTS idx_pg_plan_capture_time + ON collect.pg_plan_capture(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (99, 'pg-plan-capture', now()::timestamp); +-- ===BATCH=== V100 pg-major-version + +ALTER TABLE collect.servers + ADD COLUMN IF NOT EXISTS postgres_major_version integer; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (100, 'pg-major-version', now()::timestamp); +-- ===BATCH=== V101 pg18-io-bytes + +ALTER TABLE collect.pg_io_stats + ADD COLUMN IF NOT EXISTS read_bytes numeric(28,0), + ADD COLUMN IF NOT EXISTS write_bytes numeric(28,0), + ADD COLUMN IF NOT EXISTS extend_bytes numeric(28,0); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (101, 'pg18-io-bytes', now()::timestamp); +-- ===BATCH=== V102 pg-server-config + +CREATE TABLE IF NOT EXISTS collect.pg_server_config ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + name text, + setting text, + unit text, + category text, + context text, + vartype text, + source text, + boot_val text, + reset_val text, + sourcefile text, + sourceline integer, + pending_restart boolean, + short_desc text, + database_name text, + role_name text +); + +CREATE INDEX IF NOT EXISTS idx_pg_server_config_time + ON collect.pg_server_config(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (102, 'pg-server-config', now()::timestamp); +-- ===BATCH=== V103 pg-deadlocks + +CREATE TABLE IF NOT EXISTS collect.pg_deadlocks ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + occurred_at timestamp, + victim_pid integer, + participant_count integer, + deadlock_hash text, + lock_modes text, + resources text, + victim_statement text, + graph_text text +); + +CREATE INDEX IF NOT EXISTS idx_pg_deadlocks_time + ON collect.pg_deadlocks(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (103, 'pg-deadlocks', now()::timestamp); +-- ===BATCH=== V104 pg-deadlock-identity-index + +CREATE INDEX IF NOT EXISTS idx_pg_deadlocks_identity + ON collect.pg_deadlocks(server_id, deadlock_hash); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (104, 'pg-deadlock-identity-index', now()::timestamp); +-- ===BATCH=== V105 collector-cost + +CREATE TABLE IF NOT EXISTS collect.collector_cost +( + metric_time timestamp NOT NULL, + server_id integer NOT NULL, + database_name text, + collector_name text NOT NULL, + run_count integer NOT NULL, + total_sql_ms bigint NOT NULL, + max_sql_ms bigint NOT NULL, + total_storage_ms bigint NOT NULL, + total_rows bigint NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_collector_cost_time + ON collect.collector_cost(metric_time); + +CREATE INDEX IF NOT EXISTS idx_collector_cost_lookup + ON collect.collector_cost(server_id, collector_name, metric_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (105, 'collector-cost', now()::timestamp); +-- ===BATCH=== V106 pg-cpu-utilization + +CREATE TABLE IF NOT EXISTS collect.pg_cpu_utilization ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + sample_time timestamp, + cpu_percent double precision, + acu_utilization_percent double precision, + serverless_capacity_acu double precision, + max_configured_acu double precision, + memory_total_bytes bigint, + memory_free_bytes bigint, + memory_cached_bytes bigint, + memory_buffers_bytes bigint, + memory_active_bytes bigint, + configured_memory_bytes bigint +); + +CREATE INDEX IF NOT EXISTS idx_pg_cpu_utilization_time + ON collect.pg_cpu_utilization(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (106, 'pg-cpu-utilization', now()::timestamp); +-- ===BATCH=== V107 plan-force-actions + +CREATE TABLE IF NOT EXISTS collect.plan_force_actions +( + action_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + action_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text NOT NULL, + query_id bigint NOT NULL, + plan_id bigint NOT NULL, + action text NOT NULL, + mode text NOT NULL, + decision text NOT NULL, + reasons text NOT NULL DEFAULT '', + regression_factor numeric(19,2) NOT NULL DEFAULT 0, + latest_cpu_per_exec_us numeric(19,2) NOT NULL DEFAULT 0, + best_cpu_per_exec_us numeric(19,2) NOT NULL DEFAULT 0, + replica_role text, + parameter_sensitivity_cofired boolean NOT NULL DEFAULT FALSE, + outcome text NOT NULL, + detail text, + related_action_id bigint +); + +CREATE INDEX IF NOT EXISTS idx_plan_force_actions_time + ON collect.plan_force_actions(server_id, action_time); + +CREATE INDEX IF NOT EXISTS idx_plan_force_actions_query + ON collect.plan_force_actions(server_id, database_name, query_id, action_time); + +ALTER TABLE config.config_monitored_servers + ADD COLUMN IF NOT EXISTS plan_force_bot_enabled boolean NOT NULL DEFAULT FALSE; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (107, 'plan-force-actions', now()::timestamp); +-- ===BATCH=== V108 collection-log-phase-split + +ALTER TABLE collect.collection_log + ADD COLUMN IF NOT EXISTS sql_open_ms integer, + ADD COLUMN IF NOT EXISTS sql_drain_ms integer, + ADD COLUMN IF NOT EXISTS watermark_ms integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so without this refresh the passthrough every + read goes through would keep serving the pre-V108 column list forever and the new columns would be + invisible to an UPGRADED store while working fine on a fresh one - the V14 lesson, and V80's too. */ +CREATE OR REPLACE VIEW collect.v_collection_log AS SELECT * FROM collect.collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (108, 'collection-log-phase-split', now()::timestamp); +-- ===BATCH=== V109 collection-log-drain-forensics + +ALTER TABLE collect.collection_log + ADD COLUMN IF NOT EXISTS drain_rows_read bigint, + ADD COLUMN IF NOT EXISTS drain_bytes_read bigint, + ADD COLUMN IF NOT EXISTS drain_last_read_ms integer, + ADD COLUMN IF NOT EXISTS target_session_id integer, + ADD COLUMN IF NOT EXISTS sweep_peer_max_ms integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so without this refresh the passthrough every + read goes through would keep serving the pre-V109 column list forever - invisible on an UPGRADED store + while working fine on a fresh one. The V14 lesson, V80's, and V108's. */ +CREATE OR REPLACE VIEW collect.v_collection_log AS SELECT * FROM collect.collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (109, 'collection-log-drain-forensics', now()::timestamp); +-- ===BATCH=== V110 collection-log-fetch-phase-sums + +ALTER TABLE collect.collection_log + ADD COLUMN IF NOT EXISTS plan_fetch_probe_ms integer, + ADD COLUMN IF NOT EXISTS plan_fetch_target_ms integer, + ADD COLUMN IF NOT EXISTS plan_fetch_write_ms integer, + ADD COLUMN IF NOT EXISTS plan_fetch_ids_attempted integer, + ADD COLUMN IF NOT EXISTS plan_fetch_probe_ids integer, + ADD COLUMN IF NOT EXISTS text_fetch_probe_ms integer, + ADD COLUMN IF NOT EXISTS text_fetch_target_ms integer, + ADD COLUMN IF NOT EXISTS text_fetch_write_ms integer, + ADD COLUMN IF NOT EXISTS text_fetch_ids_attempted integer, + ADD COLUMN IF NOT EXISTS text_fetch_probe_ids integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so without this refresh the passthrough every + read goes through would keep serving the pre-V110 column list forever - invisible on an UPGRADED store + while working fine on a fresh one. The V14 lesson, V80's, V108's and V109's. */ +CREATE OR REPLACE VIEW collect.v_collection_log AS SELECT * FROM collect.collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (110, 'collection-log-fetch-phase-sums', now()::timestamp); +-- ===BATCH=== V111 store-log-self-monitoring + +CREATE TABLE IF NOT EXISTS collect.store_log_events +( + capture_time timestamp NOT NULL, + event_class text NOT NULL, + severity text NOT NULL, + occurrences integer NOT NULL, + message_text text, + sample_line text +); + +CREATE INDEX IF NOT EXISTS idx_store_log_events_time + ON collect.store_log_events(capture_time); + +CREATE INDEX IF NOT EXISTS idx_store_log_events_class + ON collect.store_log_events(event_class, capture_time); + +CREATE TABLE IF NOT EXISTS collect.store_log_captures +( + capture_time timestamp NOT NULL, + log_file text NOT NULL, + bytes_read bigint NOT NULL, + bytes_pending bigint NOT NULL, + lines_read integer NOT NULL, + entries_read integer NOT NULL, + offset_reset boolean NOT NULL, + groups_dropped integer NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_store_log_captures_time + ON collect.store_log_captures(capture_time); + +CREATE TABLE IF NOT EXISTS config.store_log_read_marker +( + log_file text NOT NULL PRIMARY KEY, + byte_offset bigint NOT NULL, + last_size bigint NOT NULL, + updated_at timestamp NOT NULL +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (111, 'store-log-self-monitoring', now()::timestamp); +-- ===BATCH=== V112 collector-stall-wait-probes + +CREATE TABLE IF NOT EXISTS collect.collector_stall_probes +( + probe_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + collector_name text NOT NULL, + outcome text NOT NULL, + budget_ms integer NOT NULL, + trigger_elapsed_ms integer NOT NULL, + trigger_rows_read bigint, + trigger_bytes_read bigint, + trigger_last_read_ms integer, + connect_ms integer, + query_ms integer, + waiting_task_count bigint, + distinct_wait_types integer, + top_wait_type text, + top_wait_total_ms bigint, + top_wait_max_ms bigint, + wait_summary text, + scheduler_count integer, + runnable_tasks bigint, + work_queue_length bigint, + pending_disk_io bigint, + max_runnable_tasks integer, + error_message text +); + +/* The read is newest-first per server, and the retention DELETE is by time alone, so one index serves both. + Not UNIQUE: two collectors on one server can stall in the same millisecond, and a unique key would drop + the second sample - the one that proves the degradation is not confined to a single collector. */ +CREATE INDEX IF NOT EXISTS idx_collector_stall_probes_time + ON collect.collector_stall_probes(server_id, probe_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (112, 'collector-stall-wait-probes', now()::timestamp); +-- ===BATCH=== V113 remediation-credential-and-actor + +ALTER TABLE config.config_monitored_servers + ADD COLUMN IF NOT EXISTS remediation_username text; + +ALTER TABLE config.config_monitored_servers + ADD COLUMN IF NOT EXISTS remediation_encrypted_password text; + +ALTER TABLE collect.plan_force_actions + ADD COLUMN IF NOT EXISTS actor text NOT NULL DEFAULT 'bot'; + +ALTER TABLE collect.plan_force_actions + ALTER COLUMN actor DROP DEFAULT; + +/* The review read is (server_id, actor, action) with an ordering on action_time, and it is the read the + own-forces-only invariant rests on, so it gets its own index rather than riding + idx_plan_force_actions_time - which leads with server_id but knows nothing about the actor and would + make every pending-review scan read the operator's rows to discard them. */ +CREATE INDEX IF NOT EXISTS idx_plan_force_actions_actor + ON collect.plan_force_actions(server_id, actor, action, action_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (113, 'remediation-credential-and-actor', now()::timestamp); +-- ===BATCH=== V114 pg-index-bloat-estimate-columns + +ALTER TABLE collect.pg_index_bloat + ADD COLUMN IF NOT EXISTS index_pages bigint, + ADD COLUMN IF NOT EXISTS table_rows bigint, + ADD COLUMN IF NOT EXISTS fillfactor integer, + ADD COLUMN IF NOT EXISTS est_tuple_bytes bigint, + ADD COLUMN IF NOT EXISTS est_leaf_pages bigint, + ADD COLUMN IF NOT EXISTS est_bloat_pct double precision, + ADD COLUMN IF NOT EXISTS est_reclaimable_bytes bigint, + ADD COLUMN IF NOT EXISTS pgstattuple_available boolean; + +DELETE FROM collect.collector_state +WHERE collector_name = 'pg_index_bloat' +AND state_key LIKE 'rotate:%'; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (114, 'pg-index-bloat-estimate-columns', now()::timestamp); +-- ===BATCH=== V115 pg-cpu-capacity-headroom + +ALTER TABLE collect.pg_cpu_utilization + ADD COLUMN IF NOT EXISTS acu_utilization_percent double precision, + ADD COLUMN IF NOT EXISTS serverless_capacity_acu double precision, + ADD COLUMN IF NOT EXISTS max_configured_acu double precision; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (115, 'pg-cpu-capacity-headroom', now()::timestamp); +-- ===BATCH=== V116 custom-alert-core + +CREATE TABLE IF NOT EXISTS config.custom_alert_rules ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name text NOT NULL UNIQUE, + definition jsonb NOT NULL, + description text, + enabled boolean NOT NULL DEFAULT TRUE, + version integer NOT NULL DEFAULT 1, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + updated_by text +); + +CREATE TABLE IF NOT EXISTS config.custom_alert_state ( + rule_id bigint NOT NULL REFERENCES config.custom_alert_rules (id) ON DELETE CASCADE, + server_id integer NOT NULL, + rule_version integer NOT NULL, + consecutive_breaches integer NOT NULL DEFAULT 0, + consecutive_clears integer NOT NULL DEFAULT 0, + firing boolean NOT NULL DEFAULT FALSE, + fired_severity text, + last_evaluated_at timestamp, + next_due_at timestamp, + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + PRIMARY KEY (rule_id, server_id) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (116, 'custom-alert-core', now()::timestamp); +-- ===BATCH=== V117 mute-rules-reload-beacon + +DROP TRIGGER IF EXISTS trg_bump_mute_rules ON config.config_mute_rules; +CREATE TRIGGER trg_bump_mute_rules + AFTER INSERT OR UPDATE OR DELETE ON config.config_mute_rules + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (117, 'mute-rules-reload-beacon', now()::timestamp); +-- ===BATCH=== V118 builtin-alert-persistence + +CREATE TABLE IF NOT EXISTS config.alert_persistence_state ( + server_id integer NOT NULL, + metric_name text NOT NULL, + consecutive_breaches integer NOT NULL DEFAULT 0, + consecutive_clears integer NOT NULL DEFAULT 0, + firing boolean NOT NULL DEFAULT FALSE, + last_observed_sample_at timestamp, + updated_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + PRIMARY KEY (server_id, metric_name) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (118, 'builtin-alert-persistence', now()::timestamp); +-- ===BATCH=== V119 retention-hold-ratio-knobs + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS retention_hold_warn_ratio double precision NOT NULL DEFAULT 2.0; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS retention_hold_critical_ratio double precision NOT NULL DEFAULT 4.0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (119, 'retention-hold-ratio-knobs', now()::timestamp); +-- ===BATCH=== V120 deadlock-rate-band-knobs + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS deadlock_warn_per_hour double precision NOT NULL DEFAULT 5.0; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS deadlock_critical_per_hour double precision NOT NULL DEFAULT 20.0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (120, 'deadlock-rate-band-knobs', now()::timestamp); +-- ===BATCH=== V121 oversized-plan-backlog + +ALTER TABLE query_stats + ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE procedure_stats + ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +DROP VIEW IF EXISTS v_query_stats; + +CREATE TABLE IF NOT EXISTS collect.oversized_plan_backlog +( + server_id integer NOT NULL, + collector_name text NOT NULL, + plan_handle text NOT NULL, + sql_handle text NOT NULL, + statement_start_offset integer NOT NULL, + statement_end_offset integer NOT NULL, + database_name text, + query_hash text, + observed_bytes bigint NOT NULL, + first_seen_at timestamp NOT NULL, + last_seen_at timestamp NOT NULL, + plan_xml text, + captured_at timestamp, + expired_at timestamp, + last_attempt_at timestamp, + attempt_count integer NOT NULL DEFAULT 0, + CONSTRAINT pk_oversized_plan_backlog PRIMARY KEY + ( + server_id, + collector_name, + plan_handle, + sql_handle, + statement_start_offset, + statement_end_offset + ) +); + +ALTER TABLE query_plan_dim + ADD COLUMN IF NOT EXISTS query_plan_gz bytea; +ALTER TABLE query_plan_dim + ALTER COLUMN query_plan_xml DROP NOT NULL; +/* Pre-adds for the payload-resolving view below: it names every payload column the + collector has today, and a store replaying this rung may predate the ALTER that adds + one of them. Idempotent, so this is a no-op wherever they already exist. */ +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS database_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS creation_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS last_execution_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_clr_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sql_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_generation_num bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS host_object_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_end_offset integer; + +/* v_query_stats resolves each row's payload: the inline column for rows written before + the dimension tables existed, the dimension row for every row written since (#1767). + Column list generated from the collector definition so it can never go stale. */ +CREATE OR REPLACE VIEW v_query_stats AS +SELECT + f.collection_id, + f.collection_time, + f.server_id, + f.server_name, + f.database_name, + f.query_hash, + f.query_plan_hash, + f.creation_time, + f.last_execution_time, + f.execution_count, + f.total_worker_time, + f.total_elapsed_time, + f.total_logical_reads, + f.total_logical_writes, + f.total_physical_reads, + f.total_clr_time, + f.total_rows, + f.total_spills, + f.min_worker_time, + f.max_worker_time, + f.min_elapsed_time, + f.max_elapsed_time, + f.min_physical_reads, + f.max_physical_reads, + f.min_rows, + f.max_rows, + f.min_dop, + f.max_dop, + f.min_grant_kb, + f.max_grant_kb, + f.min_used_grant_kb, + f.max_used_grant_kb, + f.min_ideal_grant_kb, + f.max_ideal_grant_kb, + f.min_reserved_threads, + f.max_reserved_threads, + f.min_used_threads, + f.max_used_threads, + f.min_spills, + f.max_spills, + COALESCE(f.query_text, qtd.query_text) AS query_text, + COALESCE(f.query_plan_xml, qpd.query_plan_xml) AS query_plan_xml, + f.sql_handle, + f.plan_handle, + f.delta_execution_count, + f.delta_worker_time, + f.delta_elapsed_time, + f.delta_logical_reads, + f.delta_logical_writes, + f.delta_physical_reads, + f.delta_rows, + f.delta_spills, + f.plan_generation_num, + f.sample_interval_seconds, + f.host_object_name, + f.query_plan_xml_bytes, + f.statement_start_offset, + f.statement_end_offset, + f.query_text_digest, + f.query_plan_digest, + qpd.query_plan_gz +FROM query_stats AS f +LEFT JOIN query_text_dim AS qtd ON qtd.digest = f.query_text_digest +LEFT JOIN query_plan_dim AS qpd ON qpd.digest = f.query_plan_digest +; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (121, 'oversized-plan-backlog', now()::timestamp); +-- ===BATCH=== V122 pg-deadlock-blocking-count-knobs + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS pg_deadlock_count_threshold integer NOT NULL DEFAULT 1; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS pg_blocking_count_threshold integer NOT NULL DEFAULT 1; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (122, 'pg-deadlock-blocking-count-knobs', now()::timestamp); +-- ===BATCH=== V123 fleet-sweep-state + +CREATE TABLE IF NOT EXISTS collect.fleet_sweep_runs +( + sweep_id bigint NOT NULL, + swept_at timestamp NOT NULL, + span_start timestamp NOT NULL, + span_end timestamp NOT NULL, + previous_sweep_id bigint, + alerts_enabled boolean NOT NULL, + servers_expected integer NOT NULL, + servers_reported integer NOT NULL, + instruments_alive boolean NOT NULL, + instrument_liveness_json text NOT NULL, + report_json text NOT NULL, + CONSTRAINT pk_fleet_sweep_runs PRIMARY KEY (sweep_id) +); + +CREATE TABLE IF NOT EXISTS collect.fleet_sweep_server_verdicts +( + sweep_id bigint NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + band text NOT NULL, + previous_band text, + band_reason text, + verdict_json text, + CONSTRAINT pk_fleet_sweep_server_verdicts PRIMARY KEY (sweep_id, server_id) +); + +CREATE TABLE IF NOT EXISTS collect.fleet_sweep_would_have_paged +( + sweep_id bigint NOT NULL, + server_id integer NOT NULL, + alert_family text NOT NULL, + evidence_json text NOT NULL, + CONSTRAINT pk_fleet_sweep_would_have_paged PRIMARY KEY (sweep_id, server_id, alert_family) +); + +CREATE TABLE IF NOT EXISTS collect.fleet_sweep_watch_items +( + server_id integer NOT NULL, + item_key text NOT NULL, + condition text NOT NULL, + state text NOT NULL, + consecutive_hits integer NOT NULL DEFAULT 0, + consecutive_misses integer NOT NULL DEFAULT 0, + first_seen_sweep_id bigint NOT NULL, + last_seen_sweep_id bigint NOT NULL, + opened_sweep_id bigint, + closed_sweep_id bigint, + first_seen_at timestamp NOT NULL, + last_seen_at timestamp NOT NULL, + evidence_json text, + CONSTRAINT pk_fleet_sweep_watch_items PRIMARY KEY (server_id, item_key) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (123, 'fleet-sweep-state', now()::timestamp); +-- ===BATCH=== V124 fleet-sweep-cadence-knobs + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS fleet_sweep_enabled boolean NOT NULL DEFAULT TRUE; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS fleet_sweep_interval_minutes integer NOT NULL DEFAULT 60; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (124, 'fleet-sweep-cadence-knobs', now()::timestamp); +-- ===BATCH=== V125 collector-database-scope + +ALTER TABLE config.config_collector_schedules + ADD COLUMN IF NOT EXISTS databases text[]; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (125, 'collector-database-scope', now()::timestamp); +-- ===BATCH=== V126 self-disk-warn-gb-floor + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS self_disk_free_warn_gb integer NOT NULL DEFAULT 50; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (126, 'self-disk-warn-gb-floor', now()::timestamp); +-- ===BATCH=== V127 delta-family-interval-columns + +ALTER TABLE collect.wait_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.file_io_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.latch_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.spinlock_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the four passthroughs would keep serving + the pre-V127 column list forever — the V14 lesson, restated by V80 and V81. Appending is the one + alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_wait_stats AS SELECT * FROM collect.wait_stats; +CREATE OR REPLACE VIEW collect.v_file_io_stats AS SELECT * FROM collect.file_io_stats; +CREATE OR REPLACE VIEW collect.v_latch_stats AS SELECT * FROM collect.latch_stats; +CREATE OR REPLACE VIEW collect.v_spinlock_stats AS SELECT * FROM collect.spinlock_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (127, 'delta-family-interval-columns', now()::timestamp); +-- ===BATCH=== V128 delta-family-interval-completion + +ALTER TABLE collect.procedure_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.memory_grant_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.pg_wait_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE collect.pg_statement_stats + ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; + +/* The delta key's two halves that were never stored. BYTE offsets into the batch's nvarchar text + (a character position is offset / 2); statement_end_offset = -1 means "to the end of the batch"; + stored raw, -1 included, because the key string carries the raw values. */ +ALTER TABLE collect.query_stats + ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE collect.query_stats + ADD COLUMN IF NOT EXISTS statement_end_offset integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the passthrough would keep serving the + pre-V128 column list forever — the V14 lesson, restated by V80, V81 and V127. The other three interval + tables have no v_ view. */ +CREATE OR REPLACE VIEW collect.v_memory_grant_stats AS SELECT * FROM collect.memory_grant_stats; + +/* v_query_stats is the payload-RESOLVING view (#1767), and its two new columns land ahead of the digest + columns — mid-list, which CREATE OR REPLACE VIEW refuses. Dropped here; the ladder entry concatenates + the regenerated resolving definition after the pre-adds, the V51/V121 idiom. */ +DROP VIEW IF EXISTS collect.v_query_stats; + +ALTER TABLE query_plan_dim + ADD COLUMN IF NOT EXISTS query_plan_gz bytea; +ALTER TABLE query_plan_dim + ALTER COLUMN query_plan_xml DROP NOT NULL; +/* Pre-adds for the payload-resolving view below: it names every payload column the + collector has today, and a store replaying this rung may predate the ALTER that adds + one of them. Idempotent, so this is a no-op wherever they already exist. */ +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS database_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_hash text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS creation_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS last_execution_time timestamp; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_clr_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS total_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_dop bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_ideal_grant_kb bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_reserved_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_used_threads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS min_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS max_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_text text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sql_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_handle text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_execution_count bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_worker_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_elapsed_time bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_logical_writes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_physical_reads bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_rows bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS delta_spills bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS plan_generation_num bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS sample_interval_seconds integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS host_object_name text; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS query_plan_xml_bytes bigint; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_start_offset integer; +ALTER TABLE query_stats ADD COLUMN IF NOT EXISTS statement_end_offset integer; + +/* v_query_stats resolves each row's payload: the inline column for rows written before + the dimension tables existed, the dimension row for every row written since (#1767). + Column list generated from the collector definition so it can never go stale. */ +CREATE OR REPLACE VIEW v_query_stats AS +SELECT + f.collection_id, + f.collection_time, + f.server_id, + f.server_name, + f.database_name, + f.query_hash, + f.query_plan_hash, + f.creation_time, + f.last_execution_time, + f.execution_count, + f.total_worker_time, + f.total_elapsed_time, + f.total_logical_reads, + f.total_logical_writes, + f.total_physical_reads, + f.total_clr_time, + f.total_rows, + f.total_spills, + f.min_worker_time, + f.max_worker_time, + f.min_elapsed_time, + f.max_elapsed_time, + f.min_physical_reads, + f.max_physical_reads, + f.min_rows, + f.max_rows, + f.min_dop, + f.max_dop, + f.min_grant_kb, + f.max_grant_kb, + f.min_used_grant_kb, + f.max_used_grant_kb, + f.min_ideal_grant_kb, + f.max_ideal_grant_kb, + f.min_reserved_threads, + f.max_reserved_threads, + f.min_used_threads, + f.max_used_threads, + f.min_spills, + f.max_spills, + COALESCE(f.query_text, qtd.query_text) AS query_text, + COALESCE(f.query_plan_xml, qpd.query_plan_xml) AS query_plan_xml, + f.sql_handle, + f.plan_handle, + f.delta_execution_count, + f.delta_worker_time, + f.delta_elapsed_time, + f.delta_logical_reads, + f.delta_logical_writes, + f.delta_physical_reads, + f.delta_rows, + f.delta_spills, + f.plan_generation_num, + f.sample_interval_seconds, + f.host_object_name, + f.query_plan_xml_bytes, + f.statement_start_offset, + f.statement_end_offset, + f.query_text_digest, + f.query_plan_digest, + qpd.query_plan_gz +FROM query_stats AS f +LEFT JOIN query_text_dim AS qtd ON qtd.digest = f.query_text_digest +LEFT JOIN query_plan_dim AS qpd ON qpd.digest = f.query_plan_digest +; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (128, 'delta-family-interval-completion', now()::timestamp); +-- ===BATCH=== V129 pg-log-events + +CREATE TABLE IF NOT EXISTS collect.pg_log_events ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + occurred_at timestamp, + family text, + severity text, + sqlstate text, + database_name text, + user_name text, + application_name text, + pid integer, + message text, + detail text, + context text, + statement_fingerprint text, + raw_line_hash text, + relation_name text, + bytes bigint, + duration_ms bigint, + pages_removed bigint, + pages_remaining bigint, + tuples_removed bigint, + tuples_remaining bigint, + buffer_hits bigint, + buffer_misses bigint, + buffer_dirtied bigint, + wal_records bigint, + wal_bytes bigint, + is_analyze boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_log_events_time + ON collect.pg_log_events(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (129, 'pg-log-events', now()::timestamp); +-- ===BATCH=== V130 pg-log-event-metrics + +ALTER TABLE collect.pg_log_events + ADD COLUMN IF NOT EXISTS relation_name text, + ADD COLUMN IF NOT EXISTS bytes bigint, + ADD COLUMN IF NOT EXISTS duration_ms bigint, + ADD COLUMN IF NOT EXISTS pages_removed bigint, + ADD COLUMN IF NOT EXISTS pages_remaining bigint, + ADD COLUMN IF NOT EXISTS tuples_removed bigint, + ADD COLUMN IF NOT EXISTS tuples_remaining bigint, + ADD COLUMN IF NOT EXISTS buffer_hits bigint, + ADD COLUMN IF NOT EXISTS buffer_misses bigint, + ADD COLUMN IF NOT EXISTS buffer_dirtied bigint, + ADD COLUMN IF NOT EXISTS wal_records bigint, + ADD COLUMN IF NOT EXISTS wal_bytes bigint, + ADD COLUMN IF NOT EXISTS is_analyze boolean; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (130, 'pg-log-event-metrics', now()::timestamp); +-- ===BATCH=== V131 notification-routes + +CREATE TABLE IF NOT EXISTS config.config_notification_routes ( + route_id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + metric_match text NOT NULL, + teams_url text NOT NULL DEFAULT '', + slack_url text NOT NULL DEFAULT '', + generic_url text NOT NULL DEFAULT '', + pagerduty_routing_key text NOT NULL DEFAULT '', + smtp_recipients text NOT NULL DEFAULT '', + configured_channels text[] GENERATED ALWAYS AS (array_remove(ARRAY[ + CASE WHEN teams_url <> '' THEN 'Teams' END, + CASE WHEN slack_url <> '' THEN 'Slack' END, + CASE WHEN generic_url <> '' THEN 'Generic' END, + CASE WHEN pagerduty_routing_key <> '' THEN 'PagerDuty' END, + CASE WHEN smtp_recipients <> '' THEN 'Email' END], NULL)) STORED, + enabled boolean NOT NULL DEFAULT TRUE, + modified_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + CONSTRAINT ck_config_notification_routes_metric_match CHECK (btrim(metric_match) <> '') +); + +DROP TRIGGER IF EXISTS trg_bump_notification_routes ON config.config_notification_routes; +CREATE TRIGGER trg_bump_notification_routes + AFTER INSERT OR UPDATE OR DELETE ON config.config_notification_routes + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (131, 'notification-routes', now()::timestamp); +-- ===BATCH=== V132 perfmon-counter-type + +ALTER TABLE collect.perfmon_stats + ADD COLUMN IF NOT EXISTS cntr_type integer; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the passthrough would keep serving the + pre-V132 column list forever — the V14 lesson, restated by V80, V81, V127 and V128. Appending is the one + alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_perfmon_stats AS SELECT * FROM collect.perfmon_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (132, 'perfmon-counter-type', now()::timestamp); +-- ===BATCH=== V133 pg-numbackends-and-sampled-ms + +ALTER TABLE collect.pg_database_stats + ADD COLUMN IF NOT EXISTS numbackends integer; + +ALTER TABLE collect.pg_wait_sampling + ADD COLUMN IF NOT EXISTS sampled_ms integer; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (133, 'pg-numbackends-and-sampled-ms', now()::timestamp); +-- ===BATCH=== V134 time-honesty + +ALTER TABLE collect.cpu_utilization_stats + ADD COLUMN IF NOT EXISTS sample_time_utc timestamp; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the passthrough would keep serving the + pre-V134 column list forever — the V14 lesson, restated by V80, V81, V127, V128 and V132. Appending is + the one alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_cpu_utilization_stats AS SELECT * FROM collect.cpu_utilization_stats; + +/* server_properties has no v_ passthrough (V16), so this ALTER stands alone. */ +ALTER TABLE collect.server_properties + ADD COLUMN IF NOT EXISTS time_zone_id text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (134, 'time-honesty', now()::timestamp); +-- ===BATCH=== V135 lrq-exclusion-knob + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS long_running_query_excluded_program_name_prefixes text[] NOT NULL + DEFAULT ARRAY['SQLAgent - TSQL JobStep']::text[]; +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS long_running_query_excluded_logins text[] NOT NULL + DEFAULT ARRAY['NT AUTHORITY\SYSTEM', 'NT AUTHORITY\NETWORK SERVICE']::text[]; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (135, 'lrq-exclusion-knob', now()::timestamp); +-- ===BATCH=== V136 pg-database-size-and-host-memory + +CREATE TABLE IF NOT EXISTS collect.pg_database_size_stats ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + size_bytes bigint, + total_bytes bigint, + is_template boolean, + allows_connections boolean +); + +CREATE INDEX IF NOT EXISTS idx_pg_database_size_stats_time + ON collect.pg_database_size_stats(server_id, collection_time); + +ALTER TABLE collect.pg_cpu_utilization + ADD COLUMN IF NOT EXISTS memory_total_bytes bigint, + ADD COLUMN IF NOT EXISTS memory_free_bytes bigint, + ADD COLUMN IF NOT EXISTS memory_cached_bytes bigint, + ADD COLUMN IF NOT EXISTS memory_buffers_bytes bigint, + ADD COLUMN IF NOT EXISTS memory_active_bytes bigint, + ADD COLUMN IF NOT EXISTS configured_memory_bytes bigint; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (136, 'pg-database-size-and-host-memory', now()::timestamp); +-- ===BATCH=== V137 qs-capture-mode-route-knob-toast-utilisation + +ALTER TABLE collect.query_store_health + ADD COLUMN IF NOT EXISTS query_capture_mode text, + ADD COLUMN IF NOT EXISTS wait_stats_capture_mode text; + +/* Postgres FREEZES a view's SELECT * column list at CREATE, so the passthrough would keep serving the + pre-V137 column list forever — the V14 lesson, restated by V80, V81, V127, V128, V132 and V134. Appending + is the one alteration CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_query_store_health AS SELECT * FROM collect.query_store_health; + +/* config_alert_settings has no v_ passthrough (V17), so this ALTER stands alone. Nullable on purpose and + nothing fills it: NULL is a value here (not set in the store; the file-level knob governs), which is what + every existing store reads the morning after the upgrade. */ +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS analysis_uncorroborated_route text; + +/* The CHECK the numeric knobs on this row do without: a route has no clamp, and an unrecognised + spelling would read as the shipped route rather than as an error. V62's guard, because ADD CONSTRAINT + has no IF NOT EXISTS. */ +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'config_alert_settings_analysis_uncorroborated_route_check' + ) THEN + ALTER TABLE config.config_alert_settings + ADD CONSTRAINT config_alert_settings_analysis_uncorroborated_route_check + CHECK (analysis_uncorroborated_route IS NULL OR analysis_uncorroborated_route IN ('digest', 'page')); + END IF; +END $$; + +/* store_metrics is a plain table with no v_ passthrough (V53), so this ALTER stands alone too. The first two + are filled only on object_kind = 'dimension' rows; toast_live_bytes is written NULL until the maintainer + decides how live bytes are measured (the rung doc carries the rig numbers). The last three belong to the + object_kind = 'checkpointer' row #3783's code half will write — deltas since the previous run of the + checkpointer's write-phase ms, sync-phase ms and requested-checkpoint count — and are NULL until then. */ +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS toast_bytes bigint, + ADD COLUMN IF NOT EXISTS toast_live_bytes bigint, + ADD COLUMN IF NOT EXISTS checkpoint_write_ms bigint, + ADD COLUMN IF NOT EXISTS checkpoint_sync_ms bigint, + ADD COLUMN IF NOT EXISTS checkpoints_requested bigint; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (137, 'qs-capture-mode-route-knob-toast-utilisation', now()::timestamp); +-- ===BATCH=== V138 pg-server-config-database-role-overrides + +/* Nullable, no DEFAULT, no backfill: catalog-only on a compressed hypertable (the V127/V128/V132/V133/V134/ + V137 shape on 2.28.1), and NULL already means what every pre-rung row is — a server-wide pg_settings row. + pg_server_config has no v_ passthrough (V102 creates none, PgSchemaGenerator.AllPassthroughViews agrees), + so the V14 frozen-column-list refresh does not apply here. Appended LAST, matching the collector's payload + order, so the positional COPY writer and an upgraded store's column order agree. */ +ALTER TABLE collect.pg_server_config + ADD COLUMN IF NOT EXISTS database_name text, + ADD COLUMN IF NOT EXISTS role_name text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (138, 'pg-server-config-database-role-overrides', now()::timestamp); +-- ===BATCH=== V139 postmaster-start-time + +/* store_metrics is a plain table with no v_ passthrough (V53). Filled on the object_kind = 'checkpointer' row only, + NULL on every other kind by the table's per-kind convention. Nullable, no DEFAULT, no backfill: a pre-rung row + cannot know which postmaster wrote it, and NULL is what the restart rule reads as no evidence. */ +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS postmaster_start_time timestamp; + +/* pg_write_stats is a compressed hypertable on the fleet; a nullable, default-less ADD COLUMN is catalog-only there + (the V127/V128/V133/V137/V138 shape). No v_ passthrough, so no view refresh. Appended LAST, matching the + collector's payload order, so the positional COPY writer and an upgraded store's column order agree. */ +ALTER TABLE collect.pg_write_stats + ADD COLUMN IF NOT EXISTS postmaster_start_time timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (139, 'postmaster-start-time', now()::timestamp); +-- ===BATCH=== V140 checkpointer-timed-count + +/* store_metrics is a plain table with no v_ passthrough (V53). Filled on the object_kind = 'checkpointer' row + only, NULL on every other kind by the table's per-kind convention. Nullable, no DEFAULT, no backfill: a + pre-rung row cannot know how many checkpoints were timed, and NULL is what the average-per-checkpoint rule + reads as unmeasured rather than zero. */ +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS checkpoints_timed bigint; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (140, 'checkpointer-timed-count', now()::timestamp); +-- ===BATCH=== V141 collection-caveats + +CREATE TABLE IF NOT EXISTS collect.analysis_collection_caveats +( + server_id integer NOT NULL, + family text NOT NULL, + reason text NOT NULL, + first_seen_utc timestamp NOT NULL, + last_seen_utc timestamp NOT NULL, + CONSTRAINT pk_analysis_collection_caveats PRIMARY KEY (server_id, family) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (141, 'collection-caveats', now()::timestamp); +-- ===BATCH=== V142 index-object-stats-server-time + +CREATE INDEX IF NOT EXISTS idx_index_object_stats_server_time ON collect.index_object_stats (server_id, collection_time DESC); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (142, 'index-object-stats-server-time', now()::timestamp); +-- ===BATCH=== V143 query-store-interval-latest + +/* One row per Regular Query Store interval identity: the raw dedup's GROUP BY plus server_id. Types and nullability + mirror query_store_stats exactly, so no row raw accepts can be refused here. fillfactor 50 keeps the open + interval's refreshes HOT (measured, #3953). */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_latest +( + server_id integer NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + replica_role text, + runtime_stats_interval_id bigint, + first_execution_time timestamp NOT NULL, + collection_time timestamp NOT NULL, + query_plan_hash text, + query_hash text, + execution_count bigint, + avg_cpu_time_us bigint, + avg_duration_us bigint, + last_execution_time timestamp, + is_forced_plan boolean, + force_failure_count bigint, + query_text text +) +WITH (fillfactor = 50); + +/* NULLS NOT DISTINCT: replica_role is NULL off an availability group, and a NULL-role re-collection must update its + row, not insert a second one. Column order is the writer's locality, not the reader's. */ +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_store_interval_latest +ON collect.query_store_interval_latest +( + server_id, + database_name, + runtime_stats_interval_id, + plan_id, + query_id, + replica_role, + first_execution_time +) +NULLS NOT DISTINCT; + +/* Per server: every raw snapshot at or after filled_since is represented (except the pending batches), and + applied_through is the newest batch accounted for. */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_latest_coverage +( + server_id integer NOT NULL, + filled_since timestamp NOT NULL, + applied_through timestamp NOT NULL, + CONSTRAINT pk_query_store_interval_latest_coverage PRIMARY KEY (server_id) +); + +/* One row per raw batch whose apply failed; it commits with that batch's raw rows, and the next apply for the + server replays it. Empty in steady state. */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_latest_pending +( + server_id integer NOT NULL, + collection_time timestamp NOT NULL, + database_name text NOT NULL, + recorded_at timestamp NOT NULL, + failure text, + CONSTRAINT pk_query_store_interval_latest_pending PRIMARY KEY (server_id, collection_time, database_name) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (143, 'query-store-interval-latest', now()::timestamp); +-- ===BATCH=== V144 raw-chunk-interval-rung-history + +CREATE TABLE IF NOT EXISTS collect.raw_chunk_interval_rung_history +( + changed_at timestamp NOT NULL, + table_name text NOT NULL, + from_interval_hours integer NOT NULL, + to_interval_hours integer NOT NULL, + reason text NOT NULL, + ingest_bytes_per_hour double precision NOT NULL, + budget_bytes double precision NOT NULL, + store_total_bytes double precision NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_raw_chunk_interval_rung_history_table_time + ON collect.raw_chunk_interval_rung_history(table_name, changed_at DESC); + +CREATE TABLE IF NOT EXISTS collect.raw_chunk_interval_reconcile_runs +( + run_at timestamp NOT NULL, + wal_bytes numeric +); + +CREATE INDEX IF NOT EXISTS idx_raw_chunk_interval_reconcile_runs_time + ON collect.raw_chunk_interval_reconcile_runs(run_at); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (144, 'raw-chunk-interval-rung-history', now()::timestamp); +-- ===BATCH=== V145 query-store-interval-wide + +/* One row per Query Store interval identity, every outcome. Types and nullability mirror query_store_stats except + first_execution_time, which stays NOT NULL here (M2, ruled): the writer's IS NOT NULL filter and coverage-reset + safeguard mean the table never silently drops a row raw accepted. fillfactor 50 keeps the open interval's + refreshes HOT, as V143's. */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_wide +( + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + execution_type_desc text, + first_execution_time timestamp NOT NULL, + last_execution_time timestamp, + module_name text, + query_text text, + query_hash text, + execution_count bigint, + avg_duration_us bigint, + min_duration_us bigint, + max_duration_us bigint, + avg_cpu_time_us bigint, + min_cpu_time_us bigint, + max_cpu_time_us bigint, + avg_logical_io_reads bigint, + min_logical_io_reads bigint, + max_logical_io_reads bigint, + avg_logical_io_writes bigint, + min_logical_io_writes bigint, + max_logical_io_writes bigint, + avg_physical_io_reads bigint, + min_physical_io_reads bigint, + max_physical_io_reads bigint, + avg_clr_time_us bigint, + min_clr_time_us bigint, + max_clr_time_us bigint, + min_dop bigint, + max_dop bigint, + avg_query_max_used_memory bigint, + min_query_max_used_memory bigint, + max_query_max_used_memory bigint, + avg_rowcount bigint, + min_rowcount bigint, + max_rowcount bigint, + avg_num_physical_io_reads bigint, + min_num_physical_io_reads bigint, + max_num_physical_io_reads bigint, + avg_log_bytes_used bigint, + min_log_bytes_used bigint, + max_log_bytes_used bigint, + avg_tempdb_space_used bigint, + min_tempdb_space_used bigint, + max_tempdb_space_used bigint, + plan_type text, + plan_forcing_type text, + is_forced_plan boolean, + force_failure_count bigint, + last_force_failure_reason text, + compatibility_level integer, + query_plan_hash text, + replica_role text, + runtime_stats_interval_id bigint, + interval_start_time_utc timestamp +) +WITH (fillfactor = 50); + +/* NULLS NOT DISTINCT, same reason as V143's: replica_role is NULL off an availability group. execution_type_desc + joins the identity because this table, unlike V143's, holds every outcome. No secondary index (F1, measured). */ +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_store_interval_wide +ON collect.query_store_interval_wide +( + server_id, + database_name, + runtime_stats_interval_id, + plan_id, + query_id, + replica_role, + first_execution_time, + execution_type_desc +) +NULLS NOT DISTINCT; + +/* Column-for-column copy of V143's coverage table: this table's own claim, independent of V143's. */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_wide_coverage +( + server_id integer NOT NULL, + filled_since timestamp NOT NULL, + applied_through timestamp NOT NULL, + CONSTRAINT pk_query_store_interval_wide_coverage PRIMARY KEY (server_id) +); + +/* Column-for-column copy of V143's pending table: one row per raw batch whose apply to THIS table failed. */ +CREATE TABLE IF NOT EXISTS collect.query_store_interval_wide_pending +( + server_id integer NOT NULL, + collection_time timestamp NOT NULL, + database_name text NOT NULL, + recorded_at timestamp NOT NULL, + failure text, + CONSTRAINT pk_query_store_interval_wide_pending PRIMARY KEY (server_id, collection_time, database_name) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (145, 'query-store-interval-wide', now()::timestamp); +-- ===BATCH=== V146 managed-conf-verdicts + +CREATE TABLE IF NOT EXISTS collect.managed_conf_verdicts +( + setting_name text NOT NULL, + current_value text NOT NULL, + derived_value text NOT NULL, + source_description text NOT NULL, + source_file text, + source_line integer, + verdict text NOT NULL, + detail text, + computed_at timestamp NOT NULL, + postmaster_start_time timestamp NOT NULL, + CONSTRAINT pk_managed_conf_verdicts PRIMARY KEY (setting_name) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (146, 'managed-conf-verdicts', now()::timestamp); +-- ===BATCH=== V147 compose-statement-timeout-sixty + +ALTER TABLE config.config_service ALTER COLUMN compose_statement_timeout_seconds SET DEFAULT 60; +UPDATE config.config_service SET compose_statement_timeout_seconds = 60 WHERE compose_statement_timeout_seconds = 15; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (147, 'compose-statement-timeout-sixty', now()::timestamp); +-- ===BATCH=== V148 read-latency + +CREATE TABLE IF NOT EXISTS collect.read_latency +( + metric_time timestamp NOT NULL, + surface text NOT NULL, + route text NOT NULL, + outcome text NOT NULL, + run_count integer NOT NULL, + total_ms bigint NOT NULL, + max_ms bigint NOT NULL, + bucket_counts bigint[] NOT NULL, + PRIMARY KEY (metric_time, surface, route, outcome) +); + +CREATE INDEX IF NOT EXISTS idx_read_latency_time + ON collect.read_latency(metric_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (148, 'read-latency', now()::timestamp); +-- ===BATCH=== V149 query-store-liveness-hot-touch + +DROP INDEX IF EXISTS collect.idx_query_store_plan_map_last_seen; +DROP INDEX IF EXISTS collect.idx_query_store_text_last_seen; +ALTER TABLE collect.query_store_plan_map SET (fillfactor = 90); +ALTER TABLE collect.query_store_text SET (fillfactor = 90); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (149, 'query-store-liveness-hot-touch', now()::timestamp); +-- ===BATCH=== V150 collection-log-watermark-and-job-history-indexes + +CREATE INDEX IF NOT EXISTS idx_collection_log_watermark + ON collect.collection_log (server_id, collector_name, collection_time DESC); +CREATE INDEX IF NOT EXISTS idx_job_history_server_run + ON collect.job_history (server_id, run_datetime DESC, instance_id DESC); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (150, 'collection-log-watermark-and-job-history-indexes', now()::timestamp); +-- ===BATCH=== V151 ag-group-id + +ALTER TABLE collect.ag_replica_states + ADD COLUMN IF NOT EXISTS group_id text; + +ALTER TABLE collect.ag_database_replica_states + ADD COLUMN IF NOT EXISTS group_id text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (151, 'ag-group-id', now()::timestamp); +-- ===BATCH=== V152 drop-unread-cagg-group-indexes + +SET LOCAL lock_timeout = '280s'; +DO $$ +DECLARE + v_view text; + v_drop_cols text[]; + v_mat_schema text; + v_mat_table text; + v_mat_oid regclass; + r record; +BEGIN + /* timescaledb_information only exists once the extension has been created, and this runs on stores + where it never was -- reaching it unconditionally raises 42P01. Probed with to_regclass (NULL rather + than an error when absent); no extension means there are no continuous aggregates and so no rollup + group indexes to drop, which makes this rung a no-op there. The per-view read below goes through + EXECUTE so the timescaledb_information reference is parsed only when it runs. */ + IF to_regclass('timescaledb_information.continuous_aggregates') IS NULL THEN + RETURN; + END IF; + + FOR v_view, v_drop_cols IN VALUES + ('query_store_stats_hourly', ARRAY['database_name', 'module_name', 'query_hash']), + ('query_store_stats_corrected_hourly', ARRAY['database_name', 'module_name', 'query_hash']), + ('query_store_stats_daily', ARRAY['database_name', 'module_name', 'query_hash', 'server_name']), + ('query_store_stats_corrected_daily', ARRAY['database_name', 'module_name', 'query_hash', 'server_name']), + ('query_store_stats_interval_daily', ARRAY['database_name', 'execution_type_desc', 'first_execution_time', 'module_name', 'plan_id', 'query_hash', 'query_id', 'replica_role', 'runtime_stats_interval_id', 'server_name']), + ('query_store_stats_daygrain_daily', ARRAY['database_name', 'module_name', 'query_hash', 'server_name']) + LOOP + EXECUTE 'SELECT materialization_hypertable_schema, materialization_hypertable_name + FROM timescaledb_information.continuous_aggregates + WHERE view_schema = ''collect'' AND view_name = $1' + INTO v_mat_schema, v_mat_table + USING v_view; + + IF v_mat_table IS NULL THEN + CONTINUE; + END IF; + + v_mat_oid := format('%I.%I', v_mat_schema, v_mat_table)::regclass; + + FOR r IN + SELECT i.indexrelid::regclass AS idx + FROM pg_index i + JOIN pg_attribute a1 ON a1.attrelid = i.indrelid AND a1.attnum = i.indkey[0] + JOIN pg_attribute a2 ON a2.attrelid = i.indrelid AND a2.attnum = i.indkey[1] + WHERE i.indrelid = v_mat_oid + AND i.indnkeyatts = 2 + AND NOT i.indisunique + AND a1.attname = ANY (v_drop_cols) + AND a2.attname = 'bucket' + LOOP + EXECUTE format('DROP INDEX IF EXISTS %s', r.idx); + END LOOP; + END LOOP; +END $$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (152, 'drop-unread-cagg-group-indexes', now()::timestamp); +-- ===BATCH=== V153 interval-tables-first-exec-index + +SET LOCAL lock_timeout = '280s'; +SET LOCAL max_parallel_maintenance_workers = 2; +CREATE INDEX IF NOT EXISTS idx_query_store_interval_latest_first_exec +ON collect.query_store_interval_latest (first_execution_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (153, 'interval-tables-first-exec-index', now()::timestamp); +-- ===BATCH=== V154 interval-tables-wide-first-exec-index + +SET LOCAL lock_timeout = '280s'; +SET LOCAL max_parallel_maintenance_workers = 2; +CREATE INDEX IF NOT EXISTS idx_query_store_interval_wide_first_exec +ON collect.query_store_interval_wide (first_execution_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (154, 'interval-tables-wide-first-exec-index', now()::timestamp); +-- ===BATCH=== V155 query-store-interval-end + +ALTER TABLE collect.query_store_stats ADD COLUMN IF NOT EXISTS interval_end_time_utc timestamp; +ALTER TABLE collect.query_store_interval_wide ADD COLUMN IF NOT EXISTS interval_end_time_utc timestamp; +CREATE OR REPLACE VIEW v_query_store_stats AS SELECT * FROM query_store_stats; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (155, 'query-store-interval-end', now()::timestamp); +-- ===BATCH=== V156 checkpoint-longest-sync + +/* store_metrics is a plain table with no v_ passthrough (V53). Filled on the object_kind = 'checkpointer' row only, + NULL on every other kind by the table's per-kind convention, and NULL there too when the sampler took no + difference in the hour. Nullable, no DEFAULT, no backfill: a pre-rung row cannot know what the sampler saw, and + NULL is what the reader judges as no evidence. The stamp is naive UTC. */ +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS checkpoint_longest_sync_ms bigint, + ADD COLUMN IF NOT EXISTS checkpoint_longest_sync_at timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (156, 'checkpoint-longest-sync', now()::timestamp); +-- ===BATCH=== V157 mute-rule-server-id +ALTER TABLE config.config_mute_rules ADD COLUMN IF NOT EXISTS server_id integer; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (157, 'mute-rule-server-id', now()::timestamp); +-- ===BATCH=== V158 install-id + +/* V158: the install id (#4961), one row, made by the service at start. Schema-qualified config.* like every rung. */ +CREATE TABLE IF NOT EXISTS config.config_install_id ( + id smallint NOT NULL PRIMARY KEY DEFAULT 1 CHECK (id = 1), + install_id text NOT NULL CONSTRAINT ck_config_install_id_format CHECK (install_id ~ '^[0-9a-f]{8}$'), + system_identifier bigint, + database_oid bigint NOT NULL, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC') +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (158, 'install-id', now()::timestamp); +-- ===BATCH=== V159 install-id-table-oid + +ALTER TABLE config.config_install_id + ADD COLUMN IF NOT EXISTS table_oid bigint, + ADD COLUMN IF NOT EXISTS server_major integer; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (159, 'install-id-table-oid', now()::timestamp); +-- ===BATCH=== V160 collector-run-time + +/* V160 (#4938): a collector's optional run time, in its own table. Schema-qualified config.* like every rung. */ +CREATE TABLE IF NOT EXISTS config.config_collector_run_times ( + server_id integer, + collector_name text NOT NULL, + run_at_minute smallint NOT NULL, + CONSTRAINT ck_config_collector_run_times_range CHECK (run_at_minute BETWEEN 0 AND 1439 OR (run_at_minute = -1 AND server_id IS NOT NULL)) +); +CREATE UNIQUE INDEX IF NOT EXISTS ux_config_collector_run_times_fleet + ON config.config_collector_run_times (collector_name) WHERE server_id IS NULL; +CREATE UNIQUE INDEX IF NOT EXISTS ux_config_collector_run_times_server + ON config.config_collector_run_times (server_id, collector_name) WHERE server_id IS NOT NULL; + +DROP TRIGGER IF EXISTS trg_bump_collector_run_times ON config.config_collector_run_times; +CREATE TRIGGER trg_bump_collector_run_times + AFTER INSERT OR UPDATE OR DELETE ON config.config_collector_run_times + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (160, 'collector-run-time', now()::timestamp); +-- ===BATCH=== V161 query-store-top-daily + +/* V161 (#5094): the daily summary for get_query_store_top's long windows. APPROXIMATE by design: a day is summarized + after it ends, so a late change to a summarized day is missed. The builder owns every write. Schema-qualified + collect.* like every rung; plain tables; timestamps are naive UTC. */ +CREATE TABLE IF NOT EXISTS collect.query_store_top_daily +( + server_id integer NOT NULL, + day date NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + query_hash text, + execution_type_desc text, + replica_role text, + module_name text, + interval_rows bigint NOT NULL, + execution_count_sum numeric, + avg_duration_us_sum numeric, + avg_duration_us_n bigint NOT NULL, + avg_cpu_time_us_sum numeric, + avg_cpu_time_us_n bigint NOT NULL, + avg_logical_io_reads_sum numeric, + avg_logical_io_reads_n bigint NOT NULL, + avg_logical_io_writes_sum numeric, + avg_logical_io_writes_n bigint NOT NULL, + avg_physical_io_reads_sum numeric, + avg_physical_io_reads_n bigint NOT NULL, + avg_rowcount_sum numeric, + avg_rowcount_n bigint NOT NULL, + last_execution_time_max timestamp, + query_plan_hash_max text, + first_execution_time_min timestamp +); + +/* NULLS NOT DISTINCT: replica_role, module_name and the other key columns are NULL for most rows, and two NULLs must + be the same group. */ +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_store_top_daily +ON collect.query_store_top_daily +( + server_id, + day, + database_name, + query_id, + plan_id, + query_hash, + execution_type_desc, + replica_role, + module_name +) +NULLS NOT DISTINCT; + +/* Which days are built, at which pass (1 = early, 2 = final), when, and how many wide-table rows the build read. */ +CREATE TABLE IF NOT EXISTS collect.query_store_top_daily_built +( + server_id integer NOT NULL, + day date NOT NULL, + pass smallint NOT NULL, + built_at timestamp NOT NULL, + source_rows bigint NOT NULL, + CONSTRAINT pk_query_store_top_daily_built PRIMARY KEY (server_id, day) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (161, 'query-store-top-daily', now()::timestamp); +-- ===BATCH=== V162 slow-reads + +CREATE TABLE IF NOT EXISTS collect.slow_reads +( + slow_read_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + read_time timestamp NOT NULL, + surface text NOT NULL, + route text NOT NULL, + outcome text NOT NULL, + total_ms integer NOT NULL, + server_id integer, + window_start timestamp, + window_end timestamp, + arguments jsonb NOT NULL, + arguments_truncated boolean NOT NULL, + source text, + source_reason text, + statements jsonb NOT NULL, + statement_count integer NOT NULL, + statements_truncated boolean NOT NULL, + error_class text, + row_count bigint +); + +/* Newest-first read and the retention sweep are both by time; the id breaks ties in the read's total order. */ +CREATE INDEX IF NOT EXISTS idx_slow_reads_time + ON collect.slow_reads(read_time, slow_read_id); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (162, 'slow-reads', now()::timestamp); +-- ===BATCH=== V163 store-statement-history + +CREATE TABLE IF NOT EXISTS collect.store_statement_captures +( + capture_time timestamp NOT NULL, + interval_seconds integer, + stats_reset timestamp, + dealloc bigint, + dealloc_delta bigint, + statements_seen integer NOT NULL, + statements_kept integer NOT NULL, + hidden_statements integer NOT NULL, + outcome text NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_store_statement_captures_time + ON collect.store_statement_captures(capture_time); + +CREATE TABLE IF NOT EXISTS collect.store_statement_history +( + capture_time timestamp NOT NULL, + interval_seconds integer NOT NULL, + role_name text NOT NULL, + queryid bigint NOT NULL, + delta_calls bigint NOT NULL, + delta_total_exec_ms double precision NOT NULL, + delta_rows bigint NOT NULL, + delta_shared_blks_hit bigint NOT NULL, + delta_shared_blks_read bigint NOT NULL, + delta_temp_blks_written bigint NOT NULL, + max_exec_ms double precision, + first_seen boolean NOT NULL, + entry_restarted boolean NOT NULL, + reset_in_interval boolean NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_store_statement_history_time + ON collect.store_statement_history(capture_time); + +CREATE INDEX IF NOT EXISTS idx_store_statement_history_query + ON collect.store_statement_history(queryid, capture_time); + +CREATE TABLE IF NOT EXISTS config.store_statement_baseline +( + role_name text NOT NULL, + queryid bigint NOT NULL, + calls bigint NOT NULL, + total_exec_ms double precision NOT NULL, + rows_returned bigint NOT NULL, + shared_blks_hit bigint NOT NULL, + shared_blks_read bigint NOT NULL, + temp_blks_written bigint NOT NULL, + captured_at timestamp NOT NULL, + CONSTRAINT pk_store_statement_baseline PRIMARY KEY (role_name, queryid) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (163, 'store-statement-history', now()::timestamp); +-- ===BATCH=== V164 query-stats-hour-ledger + +CREATE TABLE IF NOT EXISTS collect.query_stats_hour_ledger +( + server_id integer NOT NULL, + server_name text NOT NULL, + bucket timestamp NOT NULL, + n bigint NOT NULL, + CONSTRAINT pk_query_stats_hour_ledger PRIMARY KEY (bucket, server_id, server_name) +); + +CREATE TABLE IF NOT EXISTS collect.query_stats_hour_ledger_state +( + id integer NOT NULL, + counted_since timestamp NOT NULL, + CONSTRAINT pk_query_stats_hour_ledger_state PRIMARY KEY (id), + CONSTRAINT ck_query_stats_hour_ledger_state_single_row CHECK (id = 1) +); + +INSERT INTO collect.query_stats_hour_ledger_state (id, counted_since) +VALUES (1, date_trunc('hour', now() AT TIME ZONE 'UTC') + interval '1 hour') +ON CONFLICT (id) DO NOTHING; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (164, 'query-stats-hour-ledger', now()::timestamp); +-- ===BATCH=== V165 password-key + +CREATE TABLE IF NOT EXISTS config.password_key +( + key_id text NOT NULL, + public_key bytea NOT NULL, + algorithm text NOT NULL, + state text NOT NULL, + replaced_reason text, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + replaced_at timestamp, + CONSTRAINT pk_password_key PRIMARY KEY (key_id), + CONSTRAINT ck_password_key_id CHECK (key_id ~ '^[0-9a-f]{16}$'), + CONSTRAINT ck_password_key_state CHECK (state IN ('current', 'replaced')), + CONSTRAINT ck_password_key_replaced_reason CHECK (replaced_reason IS NULL OR replaced_reason IN ('reset', 'rotated')), + CONSTRAINT ck_password_key_algorithm CHECK (algorithm IN ('RSA3072-OAEP-SHA256/A256GCM')), + CONSTRAINT ck_password_key_public_key_size CHECK (octet_length(public_key) BETWEEN 256 AND 2048), + CONSTRAINT ck_password_key_replaced_columns CHECK ( + (state = 'current' AND replaced_reason IS NULL AND replaced_at IS NULL) + OR (state = 'replaced' AND replaced_reason IS NOT NULL AND replaced_at IS NOT NULL)), + CONSTRAINT ck_password_key_id_matches_key CHECK (key_id = left(encode(sha256(public_key), 'hex'), 16)) +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_password_key_current ON config.password_key ((true)) WHERE state = 'current'; + +CREATE TABLE IF NOT EXISTS config.password_key_service +( + service_host text NOT NULL, + key_id text, + state text NOT NULL, + note text, + updated_at timestamp NOT NULL, + CONSTRAINT pk_password_key_service PRIMARY KEY (service_host), + CONSTRAINT ck_password_key_service_state CHECK (state IN ('loading', 'ok', 'missing', 'mismatch', 'refused', 'reset_pending')) +); + +CREATE TABLE IF NOT EXISTS config.legacy_secret_pin +( + server_id integer NOT NULL, + slot text NOT NULL, + value_sha256 bytea NOT NULL, + binding_sha256 bytea NOT NULL, + pinned_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + CONSTRAINT pk_legacy_secret_pin PRIMARY KEY (server_id, slot), + CONSTRAINT ck_legacy_secret_pin_slot CHECK (slot IN ('server', 'remediation', 'smtp')) +); + +CREATE TABLE IF NOT EXISTS config.legacy_secret_pin_marker +( + id integer NOT NULL, + state text NOT NULL, + changed_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + CONSTRAINT pk_legacy_secret_pin_marker PRIMARY KEY (id), + CONSTRAINT ck_legacy_secret_pin_marker_single_row CHECK (id = 1), + CONSTRAINT ck_legacy_secret_pin_marker_state CHECK (state IN ('pending', 'done', 'skipped')) +); + +INSERT INTO config.legacy_secret_pin_marker (id, state) +VALUES (1, 'pending') +ON CONFLICT (id) DO NOTHING; + +-- The two pin tables carry no row-security policy, so only the owner and superusers see their rows. +ALTER TABLE config.legacy_secret_pin ENABLE ROW LEVEL SECURITY; +ALTER TABLE config.legacy_secret_pin_marker ENABLE ROW LEVEL SECURITY; + +CREATE OR REPLACE FUNCTION config.password_key_owner_only() RETURNS trigger +LANGUAGE plpgsql +SET search_path = pg_catalog, pg_temp +AS $fn$ +BEGIN + IF pg_catalog.pg_has_role( + session_user, + (SELECT c.relowner FROM pg_catalog.pg_class AS c WHERE c.oid = TG_RELID), + 'USAGE') IS NOT TRUE THEN + RAISE EXCEPTION 'Only the store owner can change the password key tables.' USING ERRCODE = 'PW010'; + END IF; + + IF TG_LEVEL = 'STATEMENT' THEN + RETURN NULL; + END IF; + + IF TG_OP = 'DELETE' THEN + RETURN OLD; + END IF; + + RETURN NEW; +END; +$fn$; + +REVOKE ALL ON FUNCTION config.password_key_owner_only() FROM PUBLIC; + +DROP TRIGGER IF EXISTS trg_password_key_owner_only_row ON config.password_key; +CREATE TRIGGER trg_password_key_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.password_key + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_password_key_owner_only_truncate ON config.password_key; +CREATE TRIGGER trg_password_key_owner_only_truncate + BEFORE TRUNCATE ON config.password_key + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); + +DROP TRIGGER IF EXISTS trg_password_key_service_owner_only_row ON config.password_key_service; +CREATE TRIGGER trg_password_key_service_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.password_key_service + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_password_key_service_owner_only_truncate ON config.password_key_service; +CREATE TRIGGER trg_password_key_service_owner_only_truncate + BEFORE TRUNCATE ON config.password_key_service + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); + +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_owner_only_row ON config.legacy_secret_pin; +CREATE TRIGGER trg_legacy_secret_pin_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.legacy_secret_pin + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_owner_only_truncate ON config.legacy_secret_pin; +CREATE TRIGGER trg_legacy_secret_pin_owner_only_truncate + BEFORE TRUNCATE ON config.legacy_secret_pin + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); + +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_marker_owner_only_row ON config.legacy_secret_pin_marker; +CREATE TRIGGER trg_legacy_secret_pin_marker_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.legacy_secret_pin_marker + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_marker_owner_only_truncate ON config.legacy_secret_pin_marker; +CREATE TRIGGER trg_legacy_secret_pin_marker_owner_only_truncate + BEFORE TRUNCATE ON config.legacy_secret_pin_marker + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); + +ALTER TABLE config.password_key ENABLE ALWAYS TRIGGER trg_password_key_owner_only_row; +ALTER TABLE config.password_key ENABLE ALWAYS TRIGGER trg_password_key_owner_only_truncate; +ALTER TABLE config.password_key_service ENABLE ALWAYS TRIGGER trg_password_key_service_owner_only_row; +ALTER TABLE config.password_key_service ENABLE ALWAYS TRIGGER trg_password_key_service_owner_only_truncate; +ALTER TABLE config.legacy_secret_pin ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_owner_only_row; +ALTER TABLE config.legacy_secret_pin ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_owner_only_truncate; +ALTER TABLE config.legacy_secret_pin_marker ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_marker_owner_only_row; +ALTER TABLE config.legacy_secret_pin_marker ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_marker_owner_only_truncate; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (165, 'password-key', now()::timestamp); +-- ===BATCH=== V166 pagerduty-auto-resolve + +ALTER TABLE config.config_notification + ADD COLUMN IF NOT EXISTS pagerduty_auto_resolve boolean NOT NULL DEFAULT FALSE; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (166, 'pagerduty-auto-resolve', now()::timestamp); +-- ===BATCH=== V167 legacy-pin-candidates + +CREATE TABLE IF NOT EXISTS config.legacy_secret_pin_candidate +( + server_id integer NOT NULL, + slot text NOT NULL, + value_sha256 bytea NOT NULL, + host text, + port integer, + engine text, + database text, + read_only_intent boolean, + auth text, + username text, + encrypt_mode text, + trust_server_certificate boolean, + multi_subnet_failover boolean, + remediation_username text, + smtp_use_ssl boolean, + captured_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + CONSTRAINT pk_legacy_secret_pin_candidate PRIMARY KEY (server_id, slot), + CONSTRAINT ck_legacy_secret_pin_candidate_slot CHECK (slot IN ('server', 'remediation', 'smtp')) +); + +ALTER TABLE config.legacy_secret_pin_candidate ENABLE ROW LEVEL SECURITY; + +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_candidate_owner_only_row ON config.legacy_secret_pin_candidate; +CREATE TRIGGER trg_legacy_secret_pin_candidate_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.legacy_secret_pin_candidate + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_legacy_secret_pin_candidate_owner_only_truncate ON config.legacy_secret_pin_candidate; +CREATE TRIGGER trg_legacy_secret_pin_candidate_owner_only_truncate + BEFORE TRUNCATE ON config.legacy_secret_pin_candidate + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); + +ALTER TABLE config.legacy_secret_pin_candidate ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_candidate_owner_only_row; +ALTER TABLE config.legacy_secret_pin_candidate ENABLE ALWAYS TRIGGER trg_legacy_secret_pin_candidate_owner_only_truncate; + + +INSERT INTO config.legacy_secret_pin_candidate + (server_id, slot, value_sha256, host, port, engine, database, read_only_intent, auth, username, encrypt_mode, + trust_server_certificate, multi_subnet_failover, remediation_username, smtp_use_ssl) +SELECT v.server_id, v.slot, pg_catalog.sha256(pg_catalog.convert_to(v.stored, 'UTF8')), v.host, v.port, v.engine, v.database, + v.read_only_intent, v.auth, v.username, v.encrypt_mode, v.trust_server_certificate, v.multi_subnet_failover, + v.remediation_username, v.smtp_use_ssl +FROM ( + SELECT s.server_id, 'server'::text AS slot, s.encrypted_password AS stored, s.host, s.port, s.engine, s.database, + s.read_only_intent, s.auth, s.username, s.encrypt_mode, s.trust_server_certificate, s.multi_subnet_failover, + NULL::text AS remediation_username, NULL::boolean AS smtp_use_ssl + FROM config.config_monitored_servers AS s + UNION ALL + SELECT s.server_id, 'remediation'::text, s.remediation_encrypted_password, s.host, s.port, s.engine, s.database, + s.read_only_intent, s.auth, s.username, s.encrypt_mode, s.trust_server_certificate, s.multi_subnet_failover, + s.remediation_username, NULL::boolean + FROM config.config_monitored_servers AS s + UNION ALL + SELECT 0, 'smtp'::text, n.smtp_encrypted_password, n.smtp_host, n.smtp_port, NULL::text, NULL::text, + NULL::boolean, NULL::text, n.smtp_username, NULL::text, NULL::boolean, NULL::boolean, + NULL::text, n.smtp_use_ssl + FROM config.config_notification AS n + WHERE n.id = 1 +) AS v +WHERE v.stored IS NOT NULL + AND v.stored !~ '^\s*$' + AND NOT pg_catalog.starts_with(v.stored, 'sealed:') + AND NOT pg_catalog.starts_with(v.stored, 'env:') + AND NOT pg_catalog.starts_with(v.stored, 'file:') + AND EXISTS (SELECT 1 FROM config.legacy_secret_pin_marker AS m WHERE m.id = 1 AND m.state = 'pending') +ON CONFLICT (server_id, slot) DO NOTHING; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (167, 'legacy-pin-candidates', now()::timestamp); +-- ===BATCH=== V168 plan-regression-daily + +/* V168 (#5448): per-day per-plan totals for PLAN_REGRESSION's closed days, and the trigger that marks a day stale when + a late row lands in it. Naive UTC throughout. The builder (the service) owns every write to the first table; the + function writes only plan_regression_daily_built, the rung's own bookkeeping table. */ +CREATE TABLE IF NOT EXISTS collect.plan_regression_daily +( + server_id integer NOT NULL, + day date NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + replica_role text, + query_plan_hash text, + execs numeric, + cpu_us_sum numeric, + dur_us_sum numeric, + last_exec timestamp, + is_forced_plan boolean, + force_failure_count bigint +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_plan_regression_daily +ON collect.plan_regression_daily (server_id, day, database_name, query_id, plan_id, replica_role, query_plan_hash) +NULLS NOT DISTINCT; + +CREATE TABLE IF NOT EXISTS collect.plan_regression_daily_built +( + server_id integer NOT NULL, + day date NOT NULL, + late_seq bigint NOT NULL DEFAULT 0, + built_seq bigint, + built_at timestamp, + source_rows bigint, + CONSTRAINT pk_plan_regression_daily_built PRIMARY KEY (server_id, day) +); + +CREATE OR REPLACE FUNCTION collect.plan_regression_daily_mark_late() RETURNS trigger +LANGUAGE plpgsql +SET search_path = pg_catalog, pg_temp +AS $f$ +/* A (server, day) is bumped at most once per transaction. The apply is one statement, so tens of + thousands of late rows would otherwise run ON CONFLICT DO UPDATE on the same one or two built rows, and each update + leaves another version of that tuple inside the one transaction: every conflict check after it walks the whole chain + (166 buffers at 30,000 versions against 4 on a fresh row), and the batch grows quadratically. One bump is enough: + the builder reads late_seq before it aggregates, and the batch's rows commit together with the bump. The pairs + already bumped are kept in a transaction-local setting (set_config(.., true)), which a rolled-back savepoint undoes + together with the bump it recorded, and which the function's own SET search_path does not touch. Each key is + server_id:day-number between commas, so one lookup is a substring test; the 17-day clamp keeps the list to at most + 17 pairs per server. After a commit the setting reads back as an empty string, not NULL. */ +DECLARE + d integer := NEW.first_execution_time::date - DATE '2000-01-01'; + marked text := coalesce(nullif(current_setting('darling.plan_regression_marked', true), ''), ','); + k0 text := ',' || NEW.server_id || ':' || d || ','; + k1 text := ',' || NEW.server_id || ':' || (d + 1) || ','; + new0 boolean := position(k0 in marked) = 0; + new1 boolean := position(k1 in marked) = 0; +BEGIN + IF NOT (new0 OR new1) THEN + RETURN NULL; + END IF; + + INSERT INTO collect.plan_regression_daily_built AS b (server_id, day, late_seq) + SELECT NEW.server_id, v.d, 1 + FROM (VALUES (NEW.first_execution_time::date, new0), (NEW.first_execution_time::date + 1, new1)) AS v (d, fresh) + WHERE v.fresh + ON CONFLICT (server_id, day) DO UPDATE SET late_seq = b.late_seq + 1; + + PERFORM set_config('darling.plan_regression_marked', + marked || CASE WHEN new0 THEN substr(k0, 2) ELSE '' END || CASE WHEN new1 THEN substr(k1, 2) ELSE '' END, true); + RETURN NULL; +END +$f$; + +DROP TRIGGER IF EXISTS trg_plan_regression_daily_late ON collect.query_store_interval_latest; +CREATE TRIGGER trg_plan_regression_daily_late + AFTER INSERT OR UPDATE ON collect.query_store_interval_latest + FOR EACH ROW + WHEN (NEW.first_execution_time < date_trunc('day', now() AT TIME ZONE 'UTC') - interval '1 day' + AND NEW.first_execution_time >= date_trunc('day', now() AT TIME ZONE 'UTC') - interval '17 days') + EXECUTE FUNCTION collect.plan_regression_daily_mark_late(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (168, 'plan-regression-daily', now()::timestamp); +-- ===BATCH=== V169 aws-per-server-role + +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS aws_role_arn text; +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS aws_external_id text; +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS aws_external_id_set boolean + GENERATED ALWAYS AS (aws_external_id IS NOT NULL) STORED; +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'config_monitored_servers_aws_role_check' + AND conrelid = 'config.config_monitored_servers'::regclass) THEN + ALTER TABLE config.config_monitored_servers + ADD CONSTRAINT config_monitored_servers_aws_role_check CHECK ( + (aws_external_id IS NULL OR aws_role_arn IS NOT NULL) + AND (aws_role_arn IS NULL OR (aws_role_arn ~ '^arn:aws(-[a-z]+)*:iam::[0-9]{12}:role/[A-Za-z0-9_+=,.@/-]+$' + AND char_length(aws_role_arn) <= 2048)) + AND (aws_external_id IS NULL OR (aws_external_id ~ '^[A-Za-z0-9_+=,.@:/-]+$' + AND char_length(aws_external_id) BETWEEN 2 AND 1224))); + END IF; +END $$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (169, 'aws-per-server-role', now()::timestamp); +-- ===BATCH=== V170 pg-io-stats-hourly +CREATE TABLE IF NOT EXISTS collect.pg_io_stats_hourly +( + server_id integer NOT NULL, + hour_start timestamp NOT NULL, + backend_type text, object_type text, context text, + row_count bigint NOT NULL, + last_ct timestamp NOT NULL, + prev_ct timestamp, + stats_reset timestamp, + op_bytes bigint, + writes_tracked boolean NOT NULL, + byte_counters_tracked boolean NOT NULL, + i_reads numeric, i_read_time_ms double precision, i_hits numeric, i_extends numeric, i_extend_time_ms double precision, + i_evictions numeric, i_reuses numeric, i_writes numeric, i_write_time_ms double precision, + i_read_bytes numeric, i_write_bytes numeric, i_extend_bytes numeric, + b_reads numeric, b_read_time_ms double precision, b_hits numeric, b_extends numeric, b_extend_time_ms double precision, + b_evictions numeric, b_reuses numeric, b_writes numeric, b_write_time_ms double precision, + b_read_bytes numeric, b_write_bytes numeric, b_extend_bytes numeric, + l_reads bigint, l_read_time_ms double precision, l_hits bigint, l_extends bigint, l_extend_time_ms double precision, + l_evictions bigint, l_reuses bigint, l_writes bigint, l_write_time_ms double precision, + l_read_bytes numeric(28,0), l_write_bytes numeric(28,0), l_extend_bytes numeric(28,0) +); +CREATE UNIQUE INDEX IF NOT EXISTS ux_pg_io_stats_hourly ON collect.pg_io_stats_hourly (server_id, hour_start, backend_type, object_type, context) NULLS NOT DISTINCT; +CREATE INDEX IF NOT EXISTS ix_pg_io_stats_hourly_combo ON collect.pg_io_stats_hourly (server_id, (ARRAY[backend_type, object_type, context]), hour_start DESC); +CREATE TABLE IF NOT EXISTS collect.pg_io_stats_hourly_state (server_id integer PRIMARY KEY, first_hour timestamp NOT NULL, built_through timestamp NOT NULL); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (170, 'pg-io-stats-hourly', now()::timestamp); +-- ===BATCH=== V171 query-store-interval-wide-partitioned + +SET LOCAL lock_timeout = '280s'; +DO $rung$ +BEGIN + IF (SELECT c.relkind FROM pg_class c WHERE c.oid = to_regclass('collect.query_store_interval_wide')) = 'p' THEN + RETURN; + END IF; + + ALTER TABLE collect.query_store_interval_wide RENAME TO query_store_interval_wide_legacy; + IF to_regclass('collect.ux_query_store_interval_wide') IS NOT NULL THEN + ALTER INDEX collect.ux_query_store_interval_wide RENAME TO ux_query_store_interval_wide_legacy; + END IF; + IF to_regclass('collect.idx_query_store_interval_wide_first_exec') IS NOT NULL THEN + ALTER INDEX collect.idx_query_store_interval_wide_first_exec RENAME TO idx_query_store_interval_wide_first_exec_legacy; + END IF; + IF to_regclass('collect.ix_query_store_interval_wide_server_first_exec') IS NOT NULL THEN + ALTER INDEX collect.ix_query_store_interval_wide_server_first_exec RENAME TO ix_query_store_interval_wide_server_first_exec_legacy; + END IF; + IF to_regclass('collect.ix_query_store_interval_wide_collection_time_brin') IS NOT NULL THEN + ALTER INDEX collect.ix_query_store_interval_wide_collection_time_brin RENAME TO ix_query_store_interval_wide_collection_time_brin_legacy; + END IF; + + CREATE TABLE collect.query_store_interval_wide (LIKE collect.query_store_interval_wide_legacy INCLUDING DEFAULTS INCLUDING STORAGE) + PARTITION BY RANGE (first_execution_time); + ALTER TABLE collect.query_store_interval_wide ATTACH PARTITION collect.query_store_interval_wide_legacy FOR VALUES FROM (MINVALUE) TO (MAXVALUE); + + CREATE UNIQUE INDEX ux_query_store_interval_wide ON ONLY collect.query_store_interval_wide (server_id, database_name, runtime_stats_interval_id, plan_id, query_id, replica_role, first_execution_time, execution_type_desc) NULLS NOT DISTINCT; + ALTER INDEX collect.ux_query_store_interval_wide ATTACH PARTITION collect.ux_query_store_interval_wide_legacy; + CREATE INDEX idx_query_store_interval_wide_first_exec ON ONLY collect.query_store_interval_wide (first_execution_time); + ALTER INDEX collect.idx_query_store_interval_wide_first_exec ATTACH PARTITION collect.idx_query_store_interval_wide_first_exec_legacy; + + IF to_regclass('collect.ix_query_store_interval_wide_server_first_exec_legacy') IS NOT NULL THEN + IF (SELECT i.indisvalid FROM pg_index i WHERE i.indexrelid = to_regclass('collect.ix_query_store_interval_wide_server_first_exec_legacy')) THEN + CREATE INDEX ix_query_store_interval_wide_server_first_exec ON ONLY collect.query_store_interval_wide (server_id, first_execution_time); + ALTER INDEX collect.ix_query_store_interval_wide_server_first_exec ATTACH PARTITION collect.ix_query_store_interval_wide_server_first_exec_legacy; + ELSE + DROP INDEX collect.ix_query_store_interval_wide_server_first_exec_legacy; + END IF; + END IF; + + IF to_regclass('collect.ix_query_store_interval_wide_collection_time_brin_legacy') IS NOT NULL THEN + IF (SELECT i.indisvalid FROM pg_index i WHERE i.indexrelid = to_regclass('collect.ix_query_store_interval_wide_collection_time_brin_legacy')) THEN + CREATE INDEX ix_query_store_interval_wide_collection_time_brin ON ONLY collect.query_store_interval_wide USING brin (collection_time) WITH (autosummarize = off); + ALTER INDEX collect.ix_query_store_interval_wide_collection_time_brin ATTACH PARTITION collect.ix_query_store_interval_wide_collection_time_brin_legacy; + ELSE + DROP INDEX collect.ix_query_store_interval_wide_collection_time_brin_legacy; + END IF; + END IF; +END +$rung$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (171, 'query-store-interval-wide-partitioned', now()::timestamp); +-- ===BATCH=== V172 query-store-interval-latest-partitioned + +SET LOCAL lock_timeout = '280s'; +DO $rung$ +BEGIN + IF (SELECT c.relkind FROM pg_class c WHERE c.oid = to_regclass('collect.query_store_interval_latest')) = 'p' THEN + RETURN; + END IF; + + ALTER TABLE collect.query_store_interval_latest RENAME TO query_store_interval_latest_legacy; + IF to_regclass('collect.ux_query_store_interval_latest') IS NOT NULL THEN + ALTER INDEX collect.ux_query_store_interval_latest RENAME TO ux_query_store_interval_latest_legacy; + END IF; + IF to_regclass('collect.idx_query_store_interval_latest_first_exec') IS NOT NULL THEN + ALTER INDEX collect.idx_query_store_interval_latest_first_exec RENAME TO idx_query_store_interval_latest_first_exec_legacy; + END IF; + IF to_regclass('collect.ix_query_store_interval_latest_server_first_exec') IS NOT NULL THEN + ALTER INDEX collect.ix_query_store_interval_latest_server_first_exec RENAME TO ix_query_store_interval_latest_server_first_exec_legacy; + END IF; + DROP TRIGGER IF EXISTS trg_plan_regression_daily_late ON collect.query_store_interval_latest_legacy; + + CREATE TABLE collect.query_store_interval_latest (LIKE collect.query_store_interval_latest_legacy INCLUDING DEFAULTS INCLUDING STORAGE) + PARTITION BY RANGE (first_execution_time); + ALTER TABLE collect.query_store_interval_latest ATTACH PARTITION collect.query_store_interval_latest_legacy FOR VALUES FROM (MINVALUE) TO (MAXVALUE); + + CREATE UNIQUE INDEX ux_query_store_interval_latest ON ONLY collect.query_store_interval_latest (server_id, database_name, runtime_stats_interval_id, plan_id, query_id, replica_role, first_execution_time) NULLS NOT DISTINCT; + ALTER INDEX collect.ux_query_store_interval_latest ATTACH PARTITION collect.ux_query_store_interval_latest_legacy; + CREATE INDEX idx_query_store_interval_latest_first_exec ON ONLY collect.query_store_interval_latest (first_execution_time); + ALTER INDEX collect.idx_query_store_interval_latest_first_exec ATTACH PARTITION collect.idx_query_store_interval_latest_first_exec_legacy; + + IF to_regclass('collect.ix_query_store_interval_latest_server_first_exec_legacy') IS NOT NULL THEN + IF (SELECT i.indisvalid FROM pg_index i WHERE i.indexrelid = to_regclass('collect.ix_query_store_interval_latest_server_first_exec_legacy')) THEN + CREATE INDEX ix_query_store_interval_latest_server_first_exec ON ONLY collect.query_store_interval_latest (server_id, first_execution_time); + ALTER INDEX collect.ix_query_store_interval_latest_server_first_exec ATTACH PARTITION collect.ix_query_store_interval_latest_server_first_exec_legacy; + ELSE + DROP INDEX collect.ix_query_store_interval_latest_server_first_exec_legacy; + END IF; + END IF; + + CREATE TRIGGER trg_plan_regression_daily_late + AFTER INSERT OR UPDATE ON collect.query_store_interval_latest + FOR EACH ROW + WHEN (NEW.first_execution_time < date_trunc('day', now() AT TIME ZONE 'UTC') - interval '1 day' + AND NEW.first_execution_time >= date_trunc('day', now() AT TIME ZONE 'UTC') - interval '17 days') + EXECUTE FUNCTION collect.plan_regression_daily_mark_late(); +END +$rung$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (172, 'query-store-interval-latest-partitioned', now()::timestamp); +-- ===BATCH=== V173 query-store-compose-stamp +SET LOCAL lock_timeout = '280s'; +/* V173 (#5582): the exact stamp-grain rollup of query_store_interval_wide, its per-(server, hour) validity record, the + hours the builder has done, and the row triggers that mark a pair stale when a row lands in (or leaves) an hour that + the builder may already have done. Naive UTC throughout. The service builds the rollup; the function writes only the + validity table, the rung's own bookkeeping. */ +CREATE TABLE IF NOT EXISTS collect.query_store_compose_stamp +( + collection_time timestamp NOT NULL, + wide_rows bigint NOT NULL, + ec_count bigint, + ec_min bigint, + ec_max bigint, + maxdur_count bigint, + maxdur_min bigint, + maxdur_max bigint, + maxcpu_count bigint, + maxcpu_min bigint, + maxcpu_max bigint, + server_id integer NOT NULL, + database_name text, + module_name text, + query_hash text, + ec_sum numeric, + maxdur_sum numeric, + maxcpu_sum numeric, + dur_wsum numeric, + cpu_wsum numeric +); + +/* No unique index: a one-day range read scans the index leaves in range, and a five-column unique key is about a third + more cold I/O than the read it would guard. The grain is held by the builder's GROUP BY and its one-transaction + DELETE and INSERT under the validity rows' locks. The index is B-tree-deduplicated (about 2,600 distinct keys a day). */ +CREATE INDEX IF NOT EXISTS ix_query_store_compose_stamp_time_server +ON collect.query_store_compose_stamp (collection_time, server_id); + +CREATE TABLE IF NOT EXISTS collect.query_store_compose_stamp_built +( + server_id integer NOT NULL, + hour timestamp NOT NULL, + late_seq bigint NOT NULL DEFAULT 0, + built_seq bigint, + built_at timestamp, + source_rows bigint, + stamp_rows bigint, + CONSTRAINT pk_query_store_compose_stamp_built PRIMARY KEY (server_id, hour) +); + +CREATE TABLE IF NOT EXISTS collect.query_store_compose_stamp_hours +( + hour timestamp NOT NULL, + built_at timestamp NOT NULL, + CONSTRAINT pk_query_store_compose_stamp_hours PRIMARY KEY (hour) +); + +CREATE OR REPLACE FUNCTION collect.query_store_compose_stamp_mark_late() RETURNS trigger +LANGUAGE plpgsql +SET search_path = pg_catalog, pg_temp +AS $f$ +/* A (server, hour) is bumped at most once per transaction, for V168's reason: an apply is one statement, so tens of + thousands of late rows would otherwise update the same validity row again and again, each update leaving another + version of the tuple inside the one transaction, and the batch grows quadratically. One bump is enough: the builder + reads late_seq before it aggregates, and the batch's rows commit together with the bump. The pairs + already bumped are kept in a transaction-local setting (set_config(.., true)), which a rolled-back savepoint undoes + together with the bump it recorded. Each key is server_id:hour-number between commas (hour-number is whole hours since + 1970-01-01), so one lookup is a substring test. After a commit the setting reads back as an empty string, not NULL. + An UPDATE marks the hour it moves a row OUT of (OLD) as well as the hour it lands in (NEW): the open interval's row is + refreshed with a newer collection_time, so a built hour loses a row. The threshold is the writer's own clock, not the + transaction start: a writer transaction open longer than the build lag could otherwise land a row in a built hour + unmarked. */ +DECLARE + threshold timestamp := date_trunc('hour', clock_timestamp() AT TIME ZONE 'UTC') - interval '1 hour'; + marked text := coalesce(nullif(current_setting('darling.query_store_compose_stamp_marked', true), ''), ','); + sn integer; + hn timestamp; + kn text; + so integer; + ho timestamp; + ko text; +BEGIN + IF NEW.collection_time < threshold THEN + sn := NEW.server_id; + hn := date_trunc('hour', NEW.collection_time); + kn := ',' || sn || ':' || (extract(epoch FROM hn)::bigint / 3600) || ','; + IF position(kn IN marked) > 0 THEN + kn := NULL; + END IF; + END IF; + + IF TG_OP = 'UPDATE' THEN + IF OLD.collection_time < threshold THEN + so := OLD.server_id; + ho := date_trunc('hour', OLD.collection_time); + ko := ',' || so || ':' || (extract(epoch FROM ho)::bigint / 3600) || ','; + IF position(ko IN marked) > 0 OR ko IS NOT DISTINCT FROM kn THEN + ko := NULL; + END IF; + END IF; + END IF; + + IF kn IS NULL AND ko IS NULL THEN + RETURN NULL; + END IF; + + INSERT INTO collect.query_store_compose_stamp_built AS b (server_id, hour, late_seq) + SELECT v.s, v.h, 1 + FROM (VALUES (sn, hn, kn), (so, ho, ko)) AS v (s, h, k) + WHERE v.k IS NOT NULL + ON CONFLICT (server_id, hour) DO UPDATE SET late_seq = b.late_seq + 1; + + PERFORM set_config('darling.query_store_compose_stamp_marked', + marked || CASE WHEN kn IS NOT NULL THEN substr(kn, 2) ELSE '' END || CASE WHEN ko IS NOT NULL THEN substr(ko, 2) ELSE '' END, true); + RETURN NULL; +END +$f$; + +/* On the partitioned PARENT, as V172 does for the latest table: a row trigger on a partitioned table fires for rows written + through it, and is cloned onto every existing leaf (the legacy table, DEFAULT, each day) and onto every leaf created or + attached later. WHEN reads the writer's clock (clock_timestamp), not the transaction start. No DELETE trigger: retention + removes only hours that no eligible window reads, and a partition move does not change the table's content. */ +DROP TRIGGER IF EXISTS trg_query_store_compose_stamp_late_ins ON collect.query_store_interval_wide; +CREATE TRIGGER trg_query_store_compose_stamp_late_ins + AFTER INSERT ON collect.query_store_interval_wide + FOR EACH ROW + WHEN (NEW.collection_time < date_trunc('hour', clock_timestamp() AT TIME ZONE 'UTC') - interval '1 hour') + EXECUTE FUNCTION collect.query_store_compose_stamp_mark_late(); + +DROP TRIGGER IF EXISTS trg_query_store_compose_stamp_late_upd ON collect.query_store_interval_wide; +CREATE TRIGGER trg_query_store_compose_stamp_late_upd + AFTER UPDATE ON collect.query_store_interval_wide + FOR EACH ROW + WHEN (OLD.collection_time < date_trunc('hour', clock_timestamp() AT TIME ZONE 'UTC') - interval '1 hour' + OR NEW.collection_time < date_trunc('hour', clock_timestamp() AT TIME ZONE 'UTC') - interval '1 hour') + EXECUTE FUNCTION collect.query_store_compose_stamp_mark_late(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (173, 'query-store-compose-stamp', now()::timestamp); +-- ===BATCH=== V174 service-version + +CREATE TABLE IF NOT EXISTS config.service_version +( + service_host text NOT NULL, + product_version text NOT NULL, + process_started_at timestamptz NOT NULL, + updated_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_service_version PRIMARY KEY (service_host) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (174, 'service-version', now()::timestamp); +-- ===BATCH=== V175 plan-regression-daily-rowcount +SET LOCAL lock_timeout = '280s'; +DO $$ +BEGIN + IF NOT EXISTS + ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = 'collect' + AND table_name = 'plan_regression_daily' + AND column_name = 'rowcount_sum' + ) + THEN + ALTER TABLE collect.plan_regression_daily ADD COLUMN rowcount_sum numeric; + UPDATE collect.plan_regression_daily_built SET late_seq = late_seq + 1; + END IF; +END +$$; + +DO $$ +BEGIN + IF NOT EXISTS + ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = 'collect' + AND table_name = 'query_store_interval_latest' + AND column_name = 'avg_rowcount' + ) + THEN + ALTER TABLE collect.query_store_interval_latest ADD COLUMN avg_rowcount bigint; + END IF; +END +$$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (175, 'plan-regression-daily-rowcount', now()::timestamp); +-- ===BATCH=== V176 procedure-stats-totals +CREATE TABLE IF NOT EXISTS collect.procedure_stats_totals +( + server_id integer NOT NULL, + collection_time timestamp NOT NULL, + database_name text, + total_elapsed_time bigint, + total_execution_count bigint, + row_count bigint NOT NULL, + max_sample_interval_seconds integer +); +CREATE UNIQUE INDEX IF NOT EXISTS ux_procedure_stats_totals ON collect.procedure_stats_totals (server_id, collection_time, database_name) NULLS NOT DISTINCT; +CREATE INDEX IF NOT EXISTS ix_procedure_stats_totals_time ON collect.procedure_stats_totals (collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (176, 'procedure-stats-totals', now()::timestamp); +-- ===BATCH=== V177 runnable-queue-alert-settings + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS runnable_queue_enabled boolean NOT NULL DEFAULT TRUE, + ADD COLUMN IF NOT EXISTS runnable_queue_warning_per_scheduler integer NOT NULL DEFAULT 8, + ADD COLUMN IF NOT EXISTS runnable_queue_critical_per_scheduler integer NOT NULL DEFAULT 16; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (177, 'runnable-queue-alert-settings', now()::timestamp); +-- ===BATCH=== V178 query-store-watermarks +CREATE TABLE IF NOT EXISTS collect.query_store_watermarks +( + server_id integer NOT NULL, + database_name text NOT NULL, + collection_time timestamp NOT NULL, + batch_max timestamp, + max_query_id bigint, + max_plan_id bigint, + CONSTRAINT pk_query_store_watermarks PRIMARY KEY (server_id, database_name, collection_time) +); +CREATE INDEX IF NOT EXISTS ix_query_store_watermarks_time ON collect.query_store_watermarks (collection_time); +CREATE TABLE IF NOT EXISTS collect.query_store_watermarks_coverage +( + singleton boolean NOT NULL DEFAULT true, + covered_since timestamp NOT NULL, + CONSTRAINT pk_query_store_watermarks_coverage PRIMARY KEY (singleton), + CONSTRAINT ck_query_store_watermarks_coverage_singleton CHECK (singleton) +); +INSERT INTO collect.query_store_watermarks_coverage (singleton, covered_since) +VALUES (true, (now() AT TIME ZONE 'UTC')) +ON CONFLICT (singleton) DO NOTHING; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (178, 'query-store-watermarks', now()::timestamp); +-- ===BATCH=== V179 client-timeouts-alert + +CREATE TABLE IF NOT EXISTS collect.attention_events ( + attention_event_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + event_time timestamp, + event_kind text, + attention_count bigint, + database_name text, + client_app_name text, + client_hostname text, + session_id integer, + request_id integer, + interrupt_duration_us bigint, + statement_fingerprint text, + statement_text text +); + +CREATE INDEX IF NOT EXISTS idx_attention_events_time ON collect.attention_events(server_id, collection_time); + +ALTER TABLE config.config_mute_rules ADD COLUMN IF NOT EXISTS client_app_pattern text; + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS client_timeouts_enabled boolean NOT NULL DEFAULT FALSE, + ADD COLUMN IF NOT EXISTS client_timeouts_warning_per_minute integer NOT NULL DEFAULT 10, + ADD COLUMN IF NOT EXISTS client_timeouts_critical_per_minute integer NOT NULL DEFAULT 60; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (179, 'client-timeouts-alert', now()::timestamp); +-- ===BATCH=== V180 external-alerts + +CREATE TABLE IF NOT EXISTS config.external_alert_source +( + source_id integer GENERATED ALWAYS AS IDENTITY, + source_name text NOT NULL, + role_name text NOT NULL, + enabled boolean NOT NULL DEFAULT true, + max_per_minute integer NOT NULL DEFAULT 60, + max_pending integer NOT NULL DEFAULT 500, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_external_alert_source PRIMARY KEY (source_id), + CONSTRAINT uq_external_alert_source_name UNIQUE (source_name), + CONSTRAINT uq_external_alert_source_role UNIQUE (role_name), + CONSTRAINT ck_external_alert_source_name CHECK (source_name ~ '^[a-z][a-z0-9_]{1,30}$') +); + +CREATE TABLE IF NOT EXISTS config.external_alert_pending +( + pending_id bigint GENERATED ALWAYS AS IDENTITY, + source_id integer NOT NULL, + kind text NOT NULL, + alert_key text NOT NULL, + severity text NOT NULL, + title text, + detail text, + server_name text, + value double precision, + submitted_at timestamptz NOT NULL DEFAULT now(), + expires_at timestamptz NOT NULL, + status text NOT NULL DEFAULT 'pending', + claimed_at timestamptz, + service_instance text, + attempts integer NOT NULL DEFAULT 0, + next_attempt_at timestamptz, + reason text, + completed_at timestamptz, + CONSTRAINT pk_external_alert_pending PRIMARY KEY (pending_id), + CONSTRAINT fk_external_alert_pending_source FOREIGN KEY (source_id) + REFERENCES config.external_alert_source (source_id) ON DELETE CASCADE, + CONSTRAINT ck_external_alert_pending_kind CHECK (kind IN ('fire', 'clear')), + CONSTRAINT ck_external_alert_pending_severity CHECK (severity IN ('warning', 'critical')), + CONSTRAINT ck_external_alert_pending_status CHECK (status IN + ('pending', 'claimed', 'delivered', 'muted', 'no_channel', 'failed', 'expired', 'interrupted', 'ignored')) +); + +CREATE INDEX IF NOT EXISTS ix_external_alert_pending_status ON config.external_alert_pending (status, pending_id); + +CREATE INDEX IF NOT EXISTS ix_external_alert_pending_source ON config.external_alert_pending (source_id, submitted_at); + +CREATE TABLE IF NOT EXISTS config.external_alert_state +( + source_id integer NOT NULL, + alert_key text NOT NULL, + server_label text NOT NULL DEFAULT '', + server_id integer NOT NULL DEFAULT 0, + server_key text NOT NULL DEFAULT '', + server_name text NOT NULL DEFAULT '', + firing boolean NOT NULL DEFAULT false, + fired_severity text, + last_fired_at timestamptz, + CONSTRAINT pk_external_alert_state PRIMARY KEY (source_id, alert_key, server_label), + CONSTRAINT fk_external_alert_state_source FOREIGN KEY (source_id) + REFERENCES config.external_alert_source (source_id) ON DELETE CASCADE +); + +ALTER TABLE config.config_mute_rules ADD COLUMN IF NOT EXISTS external_source text; + +DO $do$ +BEGIN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.external_alert_source, config.external_alert_pending, config.external_alert_state FROM PUBLIC; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'admin') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.external_alert_source, config.external_alert_pending, config.external_alert_state FROM admin; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'viewer') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.external_alert_source, config.external_alert_pending, config.external_alert_state FROM viewer; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'mcp') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.external_alert_source, config.external_alert_pending, config.external_alert_state FROM mcp; + END IF; +END $do$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (180, 'external-alerts', now()::timestamp); +-- ===BATCH=== V181 notification-route-scope + +ALTER TABLE config.config_notification_routes + ADD COLUMN IF NOT EXISTS scope_server_id integer, + ADD COLUMN IF NOT EXISTS scope_tag_id integer; + +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_one_scope' + AND conrelid = 'config.config_notification_routes'::regclass) THEN + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_one_scope + CHECK (scope_server_id IS NULL OR scope_tag_id IS NULL); + END IF; + + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_wildcard_scoped' + AND conrelid = 'config.config_notification_routes'::regclass) THEN + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_wildcard_scoped + CHECK (btrim(metric_match) <> '*' OR scope_server_id IS NOT NULL OR scope_tag_id IS NOT NULL) NOT VALID; + END IF; +END $$; + +DROP TRIGGER IF EXISTS trg_bump_server_tags ON config.server_tags; +CREATE TRIGGER trg_bump_server_tags + AFTER INSERT OR UPDATE OR DELETE ON config.server_tags + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +DROP TRIGGER IF EXISTS trg_bump_server_tag_map ON config.server_tag_map; +CREATE TRIGGER trg_bump_server_tag_map + AFTER INSERT OR UPDATE OR DELETE ON config.server_tag_map + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (181, 'notification-route-scope', now()::timestamp); +-- ===BATCH=== V182 read-latency-capacity-fields + +ALTER TABLE collect.read_latency + ADD COLUMN IF NOT EXISTS window_band text NOT NULL DEFAULT 'none', + ADD COLUMN IF NOT EXISTS max_in_flight integer NOT NULL DEFAULT 0, + ADD COLUMN IF NOT EXISTS wait_total_ms bigint NOT NULL DEFAULT 0; + +DO $$ +BEGIN + IF NOT EXISTS + ( + SELECT 1 + FROM pg_constraint AS c + JOIN pg_attribute AS a + ON a.attrelid = c.conrelid + AND a.attnum = ANY (c.conkey) + WHERE c.conrelid = 'collect.read_latency'::regclass + AND c.contype = 'p' + AND a.attname = 'window_band' + ) + THEN + ALTER TABLE collect.read_latency DROP CONSTRAINT IF EXISTS read_latency_pkey; + ALTER TABLE collect.read_latency + ADD CONSTRAINT read_latency_pkey PRIMARY KEY (metric_time, surface, route, outcome, window_band); + END IF; +END $$; + +ALTER TABLE collect.slow_reads + ADD COLUMN IF NOT EXISTS in_flight integer, + ADD COLUMN IF NOT EXISTS wait_ms bigint; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (182, 'read-latency-capacity-fields', now()::timestamp); +-- ===BATCH=== V183 read-caller + +ALTER TABLE collect.slow_reads + ADD COLUMN IF NOT EXISTS caller text; + +ALTER TABLE collect.read_latency + ADD COLUMN IF NOT EXISTS distinct_callers integer NOT NULL DEFAULT 0; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (183, 'read-caller', now()::timestamp); +-- ===BATCH=== V184 agent-investigations + +ALTER TABLE config.config_notification_routes + ADD COLUMN IF NOT EXISTS agent_level smallint, + ADD COLUMN IF NOT EXISTS agent_max_per_hour integer NOT NULL DEFAULT 20, + ADD COLUMN IF NOT EXISTS agent_max_per_day integer NOT NULL DEFAULT 100, + ADD COLUMN IF NOT EXISTS agent_lease_minutes integer NOT NULL DEFAULT 15, + ADD COLUMN IF NOT EXISTS agent_expiry_minutes integer NOT NULL DEFAULT 240; + +DO $do$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_agent' + AND conrelid = 'config.config_notification_routes'::regclass) THEN + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_agent CHECK ( + (agent_level IS NULL OR agent_level IN (0, 1)) + AND agent_max_per_hour BETWEEN 1 AND 60 + AND agent_max_per_day BETWEEN 1 AND 500 + AND agent_lease_minutes BETWEEN 5 AND 120 + AND agent_expiry_minutes BETWEEN 15 AND 1440); + END IF; +END $do$; + +CREATE TABLE IF NOT EXISTS config.investigation_requests +( + request_id uuid NOT NULL, + route_id integer NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + family text NOT NULL, + first_metric text NOT NULL, + first_dedup_key text, + story_path_hash text, + first_alert_at timestamptz NOT NULL, + last_alert_at timestamptz NOT NULL, + window_until timestamptz NOT NULL, + alert_count integer NOT NULL DEFAULT 1, + state text NOT NULL DEFAULT 'open', + autonomy_level smallint NOT NULL DEFAULT 1, + opened_at timestamptz NOT NULL DEFAULT now(), + expires_at timestamptz NOT NULL, + lease_minutes integer NOT NULL DEFAULT 15, + claimed_by text, + claim_id uuid, + claimed_at timestamptz, + lease_until timestamptz, + claim_count integer NOT NULL DEFAULT 0, + brief_format smallint, + brief jsonb, + reported_at timestamptz, + closed_at timestamptz, + closed_by text, + closed_reason text, + CONSTRAINT pk_investigation_requests PRIMARY KEY (request_id), + CONSTRAINT ck_investigation_requests_family CHECK (family IN + ('blocking', 'query_performance', 'resources', 'availability', 'jobs', 'self_monitor', 'other')), + CONSTRAINT ck_investigation_requests_state CHECK (state IN ('open', 'claimed', 'reported', 'closed', 'expired')), + CONSTRAINT ck_investigation_requests_autonomy CHECK (autonomy_level = 1), + CONSTRAINT ck_investigation_requests_claim_count CHECK (claim_count BETWEEN 0 AND 3), + CONSTRAINT ck_investigation_requests_claimed_by CHECK (claimed_by IS NULL OR claimed_by ~ '^[A-Za-z0-9._:-]{1,64}$') +); + +CREATE INDEX IF NOT EXISTS ix_investigation_requests_server_family ON config.investigation_requests (server_id, family, state); + +CREATE INDEX IF NOT EXISTS ix_investigation_requests_route_opened ON config.investigation_requests (route_id, opened_at); + +CREATE INDEX IF NOT EXISTS ix_investigation_requests_state_expires ON config.investigation_requests (state, expires_at); + +CREATE TABLE IF NOT EXISTS config.investigation_request_alerts +( + request_alert_id bigint GENERATED ALWAYS AS IDENTITY, + request_id uuid NOT NULL, + alert_time timestamptz NOT NULL, + server_id integer NOT NULL, + metric_name text NOT NULL, + dedup_key text, + CONSTRAINT pk_investigation_request_alerts PRIMARY KEY (request_alert_id), + CONSTRAINT fk_investigation_request_alerts_request FOREIGN KEY (request_id) + REFERENCES config.investigation_requests (request_id) ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS ix_investigation_request_alerts_request ON config.investigation_request_alerts (request_id, alert_time); + +CREATE INDEX IF NOT EXISTS ix_investigation_request_alerts_dedup ON config.investigation_request_alerts (dedup_key) WHERE dedup_key IS NOT NULL; + +CREATE TABLE IF NOT EXISTS config.investigation_reports +( + report_id bigint GENERATED ALWAYS AS IDENTITY, + request_id uuid NOT NULL, + report_format smallint NOT NULL, + agent_id text NOT NULL, + claim_id uuid NOT NULL, + submitted_at timestamptz NOT NULL DEFAULT now(), + verdict text NOT NULL, + root_cause text NOT NULL, + root_cause_found boolean NOT NULL DEFAULT false, + summary text, + evidence jsonb NOT NULL, + server_id integer NOT NULL, + metric_name text, + dedup_key text, + story_path_hash text, + CONSTRAINT pk_investigation_reports PRIMARY KEY (report_id), + CONSTRAINT uq_investigation_reports_request UNIQUE (request_id), + CONSTRAINT fk_investigation_reports_request FOREIGN KEY (request_id) + REFERENCES config.investigation_requests (request_id) ON DELETE CASCADE, + CONSTRAINT ck_investigation_reports_verdict CHECK (verdict IN ('real', 'false_positive', 'needs_person')), + CONSTRAINT ck_investigation_reports_summary CHECK (summary IS NULL OR length(summary) <= 4000), + CONSTRAINT ck_investigation_reports_evidence CHECK (jsonb_typeof(evidence) = 'array' AND jsonb_array_length(evidence) >= 1), + CONSTRAINT ck_investigation_reports_agent CHECK (agent_id ~ '^[A-Za-z0-9._:-]{1,64}$'), + CONSTRAINT ck_investigation_reports_root_cause CHECK (length(root_cause) <= 8000), + CONSTRAINT ck_investigation_reports_evidence_size CHECK ( + jsonb_array_length(evidence) <= 50 + AND octet_length(evidence::text) <= 32768 + AND NOT jsonb_path_exists(evidence, 'strict $.** ? (@.type() == "string" && @ like_regex "^(?:.{200}){5}." flag "s")')) +); + +CREATE INDEX IF NOT EXISTS ix_investigation_reports_story ON config.investigation_reports (story_path_hash, submitted_at); + +CREATE INDEX IF NOT EXISTS ix_investigation_reports_server ON config.investigation_reports (server_id, submitted_at); + +CREATE TABLE IF NOT EXISTS config.investigation_journal +( + journal_id bigint GENERATED ALWAYS AS IDENTITY, + event_time timestamptz NOT NULL DEFAULT now(), + request_id uuid, + route_id integer, + server_id integer, + event text NOT NULL, + actor text NOT NULL, + reason text, + detail jsonb, + once_key text, + CONSTRAINT pk_investigation_journal PRIMARY KEY (journal_id), + CONSTRAINT ck_investigation_journal_event CHECK (event ~ '^[a-z][a-z_]{1,40}$') +); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_journal_once ON config.investigation_journal (once_key) WHERE once_key IS NOT NULL; + +CREATE INDEX IF NOT EXISTS ix_investigation_journal_time ON config.investigation_journal (event_time); + +CREATE INDEX IF NOT EXISTS ix_investigation_journal_request ON config.investigation_journal (request_id, event_time) WHERE request_id IS NOT NULL; + +CREATE TABLE IF NOT EXISTS config.investigation_notes +( + note_id bigint GENERATED ALWAYS AS IDENTITY, + server_id integer, + story_path_hash text, + dedup_key text, + metric_name text, + note_text text NOT NULL, + author text NOT NULL, + source_request_id uuid, + state text NOT NULL DEFAULT 'pending', + created_at timestamptz NOT NULL DEFAULT now(), + expires_at timestamptz NOT NULL DEFAULT (now() + interval '90 days'), + decided_at timestamptz, + decided_by text, + CONSTRAINT pk_investigation_notes PRIMARY KEY (note_id), + CONSTRAINT ck_investigation_notes_text CHECK (btrim(note_text) <> '' AND length(note_text) <= 2000), + CONSTRAINT ck_investigation_notes_state CHECK (state IN ('pending', 'approved', 'rejected')) +); + +CREATE INDEX IF NOT EXISTS ix_investigation_notes_server ON config.investigation_notes (server_id, state); + +CREATE TABLE IF NOT EXISTS config.agent_environment_profiles +( + profile_id integer GENERATED ALWAYS AS IDENTITY, + scope_server_id integer, + scope_tag_id integer, + profile_text text NOT NULL, + modified_at timestamptz NOT NULL DEFAULT now(), + modified_by text, + CONSTRAINT pk_agent_environment_profiles PRIMARY KEY (profile_id), + CONSTRAINT ck_agent_environment_profiles_one_scope CHECK (scope_server_id IS NULL OR scope_tag_id IS NULL), + CONSTRAINT ck_agent_environment_profiles_text CHECK (length(profile_text) <= 4000) +); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_agent_environment_profiles_scope + ON config.agent_environment_profiles ((coalesce(scope_server_id, 0)), (coalesce(scope_tag_id, 0))); + +DO $do$ +BEGIN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.investigation_requests, config.investigation_request_alerts, config.investigation_reports, config.investigation_journal, config.investigation_notes, config.agent_environment_profiles FROM PUBLIC; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'admin') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.investigation_requests, config.investigation_request_alerts, config.investigation_reports, config.investigation_journal, config.investigation_notes, config.agent_environment_profiles FROM admin; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'viewer') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.investigation_requests, config.investigation_request_alerts, config.investigation_reports, config.investigation_journal, config.investigation_notes, config.agent_environment_profiles FROM viewer; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'mcp') THEN + REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON config.investigation_requests, config.investigation_request_alerts, config.investigation_reports, config.investigation_journal, config.investigation_notes, config.agent_environment_profiles FROM mcp; + END IF; +END $do$; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (184, 'agent-investigations', now()::timestamp); +-- ===BATCH=== V185 plan-regression-partial-days + +ALTER TABLE collect.plan_regression_daily_built + ADD COLUMN IF NOT EXISTS built_through timestamp, + ADD COLUMN IF NOT EXISTS partial_seq bigint; + +DROP TRIGGER IF EXISTS trg_plan_regression_daily_late ON collect.query_store_interval_latest; +CREATE TRIGGER trg_plan_regression_daily_late + AFTER INSERT OR UPDATE ON collect.query_store_interval_latest + FOR EACH ROW + WHEN (NEW.first_execution_time < date_trunc('hour', now() AT TIME ZONE 'UTC') - interval '2 hour' + AND NEW.first_execution_time >= date_trunc('day', now() AT TIME ZONE 'UTC') - interval '17 days') + EXECUTE FUNCTION collect.plan_regression_daily_mark_late(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (185, 'plan-regression-partial-days', now()::timestamp); +-- ===BATCH=== V186 collection-log-hourly + +CREATE TABLE IF NOT EXISTS collect.collection_log_hourly +( + server_id integer NOT NULL, + collector_name text NOT NULL, + hour_start timestamp NOT NULL, + total_runs integer NOT NULL, + success_count integer NOT NULL, + error_count integer NOT NULL, + permission_denied_count integer NOT NULL, + yield_count integer NOT NULL, + abandoned_count integer NOT NULL, + extension_missing_count integer NOT NULL, + session_missing_count integer NOT NULL, + note_count integer NOT NULL, + runs_with_rows integer NOT NULL, + rows_stored bigint NOT NULL, + duration_sum bigint NOT NULL, + duration_count integer NOT NULL, + max_duration_ms integer, + max_slowest_item_ms integer, + last_success_time timestamp, + last_run_time timestamp NOT NULL, + last_error_time timestamp, + last_failure_text_time timestamp, + last_note_time timestamp, + last_denied_time timestamp, + last_non_skip_time timestamp, + last_productive_time timestamp, + last_streak_break_time timestamp, + duration_histogram integer[] NOT NULL, + CONSTRAINT pk_collection_log_hourly PRIMARY KEY (server_id, collector_name, hour_start) +); + +CREATE INDEX IF NOT EXISTS idx_collection_log_hourly_hour ON collect.collection_log_hourly (hour_start); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (186, 'collection-log-hourly', now()::timestamp); +-- ===BATCH=== V187 alert-resolution-delivery + +ALTER TABLE config.config_notification + ADD COLUMN IF NOT EXISTS slack_send_resolutions boolean NOT NULL DEFAULT FALSE, + ADD COLUMN IF NOT EXISTS teams_send_resolutions boolean NOT NULL DEFAULT FALSE, + ADD COLUMN IF NOT EXISTS generic_send_resolutions boolean NOT NULL DEFAULT FALSE, + ADD COLUMN IF NOT EXISTS email_send_resolutions boolean NOT NULL DEFAULT FALSE; + +ALTER TABLE config.config_notification_routes + ADD COLUMN IF NOT EXISTS send_resolutions boolean; + +ALTER TABLE config.config_alert_log + ADD COLUMN IF NOT EXISTS resolution_sent_at timestamp, + ADD COLUMN IF NOT EXISTS resolution_channels text, + ADD COLUMN IF NOT EXISTS resolution_outcome text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (187, 'alert-resolution-delivery', now()::timestamp); +-- ===BATCH=== V188 investigation-alert-facts + +ALTER TABLE config.investigation_request_alerts + ADD COLUMN IF NOT EXISTS current_value double precision, + ADD COLUMN IF NOT EXISTS threshold_value double precision, + ADD COLUMN IF NOT EXISTS muted boolean, + ADD COLUMN IF NOT EXISTS detail_text text, + ADD COLUMN IF NOT EXISTS context_json text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (188, 'investigation-alert-facts', now()::timestamp); +-- ===BATCH=== V189 query-store-compose-failures +/* V189 (#5867): one row per Query Store compose hour whose last build failed: how many times in a row, the last error, and when + the builder tries it again. The builder deletes the row when the hour builds. Naive UTC throughout. */ +CREATE TABLE IF NOT EXISTS collect.query_store_compose_stamp_failures +( + hour timestamp NOT NULL, + failures integer NOT NULL, + last_sqlstate text, + last_reason text NOT NULL, + last_timeout_seconds integer NOT NULL, + first_failed_at timestamp NOT NULL, + last_failed_at timestamp NOT NULL, + retry_at timestamp NOT NULL, + CONSTRAINT pk_query_store_compose_stamp_failures PRIMARY KEY (hour) +); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (189, 'query-store-compose-failures', now()::timestamp); +-- ===BATCH=== V190 store-metrics-size-estimated + +ALTER TABLE collect.store_metrics + ADD COLUMN IF NOT EXISTS size_estimated boolean; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (190, 'store-metrics-size-estimated', now()::timestamp); +-- ===BATCH=== V191 agent-level-2-store + +DO $do$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_agent' + AND conrelid = 'config.config_notification_routes'::regclass + AND pg_get_constraintdef(oid) !~ 'ARRAY\[0, 1, 2\]') THEN + ALTER TABLE config.config_notification_routes DROP CONSTRAINT ck_config_notification_routes_agent; + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_agent CHECK ( + (agent_level IS NULL OR agent_level IN (0, 1, 2)) + AND agent_max_per_hour BETWEEN 1 AND 60 + AND agent_max_per_day BETWEEN 1 AND 500 + AND agent_lease_minutes BETWEEN 5 AND 120 + AND agent_expiry_minutes BETWEEN 15 AND 1440); + END IF; + + IF EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_investigation_requests_autonomy' + AND conrelid = 'config.investigation_requests'::regclass + AND pg_get_constraintdef(oid) !~ 'ARRAY\[1, 2\]') THEN + ALTER TABLE config.investigation_requests DROP CONSTRAINT ck_investigation_requests_autonomy; + ALTER TABLE config.investigation_requests + ADD CONSTRAINT ck_investigation_requests_autonomy CHECK (autonomy_level IN (1, 2)); + END IF; +END $do$; + +ALTER TABLE config.config_service + ADD COLUMN IF NOT EXISTS agent_actions_enabled boolean NOT NULL DEFAULT true; + +ALTER TABLE config.investigation_requests + ADD COLUMN IF NOT EXISTS practice_of uuid; + +CREATE TABLE IF NOT EXISTS config.config_threshold_overrides +( + id bigint GENERATED ALWAYS AS IDENTITY, + server_id integer NOT NULL, + database_name text, + threshold_key text NOT NULL, + value double precision NOT NULL, + set_by text NOT NULL, + request_id uuid, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_config_threshold_overrides PRIMARY KEY (id), + CONSTRAINT fk_config_threshold_overrides_server FOREIGN KEY (server_id) + REFERENCES config.config_monitored_servers (server_id) ON DELETE CASCADE, + CONSTRAINT ck_config_threshold_overrides_key CHECK (btrim(threshold_key) <> ''), + CONSTRAINT ck_config_threshold_overrides_set_by CHECK (btrim(set_by) <> '') +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_config_threshold_overrides_scope + ON config.config_threshold_overrides (server_id, (coalesce(database_name, '')), threshold_key); + +DROP TRIGGER IF EXISTS trg_bump_threshold_overrides ON config.config_threshold_overrides; +CREATE TRIGGER trg_bump_threshold_overrides + AFTER INSERT OR UPDATE OR DELETE ON config.config_threshold_overrides + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); + +CREATE TABLE IF NOT EXISTS config.investigation_feedback +( + id bigint GENERATED ALWAYS AS IDENTITY, + request_id uuid NOT NULL, + verdict text NOT NULL, + corrected_verdict text, + missed_step text, + comment text, + author text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_investigation_feedback PRIMARY KEY (id), + CONSTRAINT fk_investigation_feedback_request FOREIGN KEY (request_id) + REFERENCES config.investigation_requests (request_id) ON DELETE CASCADE, + CONSTRAINT ck_investigation_feedback_verdict CHECK (verdict IN ('right', 'partly', 'wrong')), + CONSTRAINT ck_investigation_feedback_corrected CHECK (corrected_verdict IS NULL OR corrected_verdict IN ('real', 'false_positive', 'needs_person')), + CONSTRAINT ck_investigation_feedback_author CHECK (author ~ '^[A-Za-z0-9._:-]{1,64}$'), + CONSTRAINT ck_investigation_feedback_missed_step CHECK (missed_step IS NULL OR length(missed_step) <= 4000), + CONSTRAINT ck_investigation_feedback_comment CHECK (comment IS NULL OR length(comment) <= 4000) +); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_feedback_author + ON config.investigation_feedback (request_id, lower(author)); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (191, 'agent-level-2-store', now()::timestamp); +-- ===BATCH=== V192 query-tags-store +CREATE TABLE IF NOT EXISTS config.query_tags ( + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name text NOT NULL, + parent_id integer REFERENCES config.query_tags(id) ON DELETE CASCADE, + sort_order integer NOT NULL DEFAULT 0, + colour text, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT ck_query_tags_name CHECK (btrim(name) <> '') +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_tags_parent_name + ON config.query_tags (COALESCE(parent_id, 0), lower(name)); + +CREATE TABLE IF NOT EXISTS config.query_tag_assignments ( + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + tag_id integer NOT NULL REFERENCES config.query_tags(id) ON DELETE CASCADE, + kind text NOT NULL, + server_id integer, + query_hash text, + database_name text, + schema_name text, + object_name text, + query_id bigint, + created_at timestamptz NOT NULL DEFAULT now(), + created_by text NOT NULL, + CONSTRAINT ck_query_tag_assignments_kind CHECK (kind IN ('hash', 'object')), + CONSTRAINT ck_query_tag_assignments_key CHECK ( + (kind = 'hash' + AND query_hash IS NOT NULL AND btrim(query_hash) <> '' + AND database_name IS NULL AND schema_name IS NULL AND object_name IS NULL) + OR + (kind = 'object' + AND query_hash IS NULL + AND database_name IS NOT NULL AND btrim(database_name) <> '' + AND schema_name IS NOT NULL AND btrim(schema_name) <> '' + AND object_name IS NOT NULL AND btrim(object_name) <> '')) +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_tag_assignments_all_servers + ON config.query_tag_assignments (kind, COALESCE(query_hash, ''), COALESCE(database_name, ''), COALESCE(schema_name, ''), COALESCE(object_name, '')) + WHERE server_id IS NULL; +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_tag_assignments_server + ON config.query_tag_assignments (server_id, kind, COALESCE(query_hash, ''), COALESCE(database_name, ''), COALESCE(schema_name, ''), COALESCE(object_name, '')) + WHERE server_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_assignments_tag + ON config.query_tag_assignments (tag_id); +CREATE INDEX IF NOT EXISTS idx_query_tag_assignments_server + ON config.query_tag_assignments (server_id) WHERE server_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_assignments_hash + ON config.query_tag_assignments (query_hash) WHERE query_hash IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_assignments_object + ON config.query_tag_assignments (object_name) WHERE object_name IS NOT NULL; + +CREATE TABLE IF NOT EXISTS config.query_tag_rules ( + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + tag_id integer REFERENCES config.query_tags(id) ON DELETE CASCADE, + priority integer NOT NULL DEFAULT 100, + enabled boolean NOT NULL DEFAULT true, + server_id integer, + match_field text NOT NULL, + pattern text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + created_by text NOT NULL, + CONSTRAINT ck_query_tag_rules_field CHECK (match_field IN ('application', 'login', 'host', 'database', 'object', 'text', 'text_tag')), + CONSTRAINT ck_query_tag_rules_tag CHECK (match_field = 'text_tag' OR tag_id IS NOT NULL), + CONSTRAINT ck_query_tag_rules_pattern CHECK (btrim(pattern) <> '') +); + +CREATE INDEX IF NOT EXISTS idx_query_tag_rules_tag + ON config.query_tag_rules (tag_id) WHERE tag_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_rules_server + ON config.query_tag_rules (server_id) WHERE server_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_rules_priority + ON config.query_tag_rules (enabled, priority, id); + +CREATE TABLE IF NOT EXISTS collect.query_tag_sightings ( + server_id integer NOT NULL, + key_kind text NOT NULL, + key text NOT NULL, + database_name text, + object_name text, + application_name text, + login_name text, + host_name text, + text_sample text, + first_seen timestamptz NOT NULL DEFAULT now(), + last_seen timestamptz NOT NULL DEFAULT now(), + seen_count bigint NOT NULL DEFAULT 1, + CONSTRAINT ck_query_tag_sightings_kind CHECK (key_kind IN ('hash', 'object', 'caller')), + CONSTRAINT ck_query_tag_sightings_sample CHECK (text_sample IS NULL OR char_length(text_sample) <= 4000), + CONSTRAINT ck_query_tag_sightings_count CHECK (seen_count >= 1) +); + +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_tag_sightings_key + ON collect.query_tag_sightings (server_id, key_kind, key, COALESCE(application_name, ''), COALESCE(login_name, ''), COALESCE(host_name, '')); +CREATE INDEX IF NOT EXISTS idx_query_tag_sightings_key + ON collect.query_tag_sightings (key_kind, key); +CREATE INDEX IF NOT EXISTS idx_query_tag_sightings_object + ON collect.query_tag_sightings (object_name) WHERE object_name IS NOT NULL; +CREATE INDEX IF NOT EXISTS idx_query_tag_sightings_last_seen + ON collect.query_tag_sightings (last_seen); + +CREATE TABLE IF NOT EXISTS config.query_tag_map ( + server_id integer NOT NULL, + key_kind text NOT NULL, + key text NOT NULL, + tag_id integer NOT NULL REFERENCES config.query_tags(id) ON DELETE CASCADE, + source text NOT NULL, + rule_id integer, + matched_field text, + matched_value text, + built_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (server_id, key_kind, key), + CONSTRAINT ck_query_tag_map_kind CHECK (key_kind IN ('hash', 'object', 'caller')), + CONSTRAINT ck_query_tag_map_source CHECK (source IN ('hand_hash', 'hand_object', 'rule')) +); + +CREATE INDEX IF NOT EXISTS idx_query_tag_map_tag + ON config.query_tag_map (tag_id); +CREATE INDEX IF NOT EXISTS idx_query_tag_map_key + ON config.query_tag_map (key_kind, key); + +CREATE TABLE IF NOT EXISTS config.query_tag_state ( + id smallint PRIMARY KEY DEFAULT 1, + rules_version bigint NOT NULL DEFAULT 1, + built_version bigint NOT NULL DEFAULT 0, + updated_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT ck_query_tag_state_one_row CHECK (id = 1) +); + +INSERT INTO config.query_tag_state (id) VALUES (1) ON CONFLICT (id) DO NOTHING; + +CREATE OR REPLACE FUNCTION config.query_tag_bump_rules_version() RETURNS trigger + LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, config +AS $fn$ +BEGIN + UPDATE config.query_tag_state SET rules_version = rules_version + 1, updated_at = now() WHERE id = 1; + RETURN NULL; +END +$fn$; + +REVOKE ALL ON FUNCTION config.query_tag_bump_rules_version() FROM PUBLIC; + +DROP TRIGGER IF EXISTS trg_bump_query_tags ON config.query_tags; +CREATE TRIGGER trg_bump_query_tags + AFTER INSERT OR UPDATE OR DELETE ON config.query_tags + FOR EACH STATEMENT EXECUTE FUNCTION config.query_tag_bump_rules_version(); + +DROP TRIGGER IF EXISTS trg_bump_query_tag_assignments ON config.query_tag_assignments; +CREATE TRIGGER trg_bump_query_tag_assignments + AFTER INSERT OR UPDATE OR DELETE ON config.query_tag_assignments + FOR EACH STATEMENT EXECUTE FUNCTION config.query_tag_bump_rules_version(); + +DROP TRIGGER IF EXISTS trg_bump_query_tag_rules ON config.query_tag_rules; +CREATE TRIGGER trg_bump_query_tag_rules + AFTER INSERT OR UPDATE OR DELETE ON config.query_tag_rules + FOR EACH STATEMENT EXECUTE FUNCTION config.query_tag_bump_rules_version(); + +COMMENT ON COLUMN config.query_tag_assignments.server_id IS 'NULL means the assignment applies to every server. A server id applies to that server only.'; +COMMENT ON COLUMN config.query_tag_assignments.query_id IS 'A display key only (a Query Store query_id as last seen). Never matched on: the hash or the object parts are the key.'; +COMMENT ON COLUMN config.query_tag_rules.server_id IS 'NULL means the rule applies to every server. A server id applies to that server only.'; +COMMENT ON COLUMN config.query_tag_rules.tag_id IS 'NULL only for the text_tag field, a rule that reads a tag name out of the statement text instead of naming one.'; +COMMENT ON COLUMN collect.query_tag_sightings.text_sample IS 'At most 4000 characters (QueryTagSchema.TextSampleMaxLength); the CHECK refuses a longer one.'; +COMMENT ON COLUMN collect.query_tag_sightings.application_name IS 'A caller field. NULL reads as an empty string in the unique key, so a sighting without it is one row, not many.'; +COMMENT ON COLUMN config.query_tag_map.rule_id IS 'The rule that produced the row. No foreign key: a deleted rule leaves its map rows until the next rebuild, which the version bump triggers.'; +COMMENT ON COLUMN config.query_tag_state.built_version IS 'The rules_version the map was last built from. The map is stale while it is below rules_version.'; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (192, 'query-tags-store', now()::timestamp); +-- ===BATCH=== V193 phase-c-store + +ALTER TABLE config.investigation_journal + ADD COLUMN IF NOT EXISTS event_id uuid NOT NULL DEFAULT gen_random_uuid(); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_journal_event_id + ON config.investigation_journal (event_id); + +ALTER TABLE config.investigation_requests + ADD COLUMN IF NOT EXISTS max_severity text, + ADD COLUMN IF NOT EXISTS evidence_state text, + ADD COLUMN IF NOT EXISTS follow_up_of uuid, + ADD COLUMN IF NOT EXISTS follow_up_at timestamptz, + ADD COLUMN IF NOT EXISTS follow_up_condition text; + +ALTER TABLE config.investigation_reports + ADD COLUMN IF NOT EXISTS family_of uuid, + ADD COLUMN IF NOT EXISTS queries_run jsonb; + +DO $do$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'fk_investigation_reports_family' + AND conrelid = 'config.investigation_reports'::regclass) THEN + ALTER TABLE config.investigation_reports + ADD CONSTRAINT fk_investigation_reports_family FOREIGN KEY (family_of) + REFERENCES config.investigation_requests (request_id) ON DELETE SET NULL; + END IF; + + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_investigation_reports_queries_run' + AND conrelid = 'config.investigation_reports'::regclass) THEN + ALTER TABLE config.investigation_reports + ADD CONSTRAINT ck_investigation_reports_queries_run CHECK ( + queries_run IS NULL OR ( + jsonb_typeof(queries_run) = 'array' + AND jsonb_array_length(queries_run) <= 20 + AND NOT jsonb_path_exists(queries_run, 'strict $.** ? (@.type() == "string" && @ like_regex "^(?:.{200}){10}." flag "s")'))); + END IF; +END $do$; + +CREATE TABLE IF NOT EXISTS config.investigation_evidence +( + evidence_id bigint GENERATED ALWAYS AS IDENTITY, + request_id uuid NOT NULL, + section text NOT NULL, + state text NOT NULL DEFAULT 'pending', + content jsonb, + captured_at timestamptz, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_investigation_evidence PRIMARY KEY (evidence_id), + CONSTRAINT uq_investigation_evidence_section UNIQUE (request_id, section), + CONSTRAINT fk_investigation_evidence_request FOREIGN KEY (request_id) + REFERENCES config.investigation_requests (request_id) ON DELETE CASCADE, + CONSTRAINT ck_investigation_evidence_section CHECK (section ~ '^[a-z][a-z0-9_]{1,40}$'), + CONSTRAINT ck_investigation_evidence_state CHECK (state IN ('pending', 'ready', 'not_collected')), + CONSTRAINT ck_investigation_evidence_content CHECK (content IS NULL OR octet_length(content::text) <= 32768) +); + +CREATE TABLE IF NOT EXISTS config.investigation_signature_days +( + server_id integer NOT NULL, + signature text NOT NULL, + day date NOT NULL, + count integer NOT NULL DEFAULT 0, + CONSTRAINT pk_investigation_signature_days PRIMARY KEY (server_id, signature, day), + CONSTRAINT ck_investigation_signature_days_signature CHECK (btrim(signature) <> ''), + CONSTRAINT ck_investigation_signature_days_count CHECK (count >= 0) +); + +CREATE INDEX IF NOT EXISTS ix_investigation_signature_days_day + ON config.investigation_signature_days (day); + +CREATE TABLE IF NOT EXISTS config.investigation_signature_merges +( + merge_id bigint GENERATED ALWAYS AS IDENTITY, + server_id integer NOT NULL, + signature text NOT NULL, + merged_into text NOT NULL, + reason text NOT NULL, + merged_by text NOT NULL, + merged_at timestamptz NOT NULL DEFAULT now(), + undone_at timestamptz, + undone_by text, + CONSTRAINT pk_investigation_signature_merges PRIMARY KEY (merge_id), + CONSTRAINT ck_investigation_signature_merges_signature CHECK (btrim(signature) <> '' AND btrim(merged_into) <> '' AND signature <> merged_into), + CONSTRAINT ck_investigation_signature_merges_reason CHECK (btrim(reason) <> '' AND length(reason) <= 2000), + CONSTRAINT ck_investigation_signature_merges_merged_by CHECK (merged_by ~ '^[A-Za-z0-9._:-]{1,64}$'), + CONSTRAINT ck_investigation_signature_merges_undone CHECK ((undone_at IS NULL) = (undone_by IS NULL)) +); + +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_signature_merges_live + ON config.investigation_signature_merges (server_id, signature) WHERE undone_at IS NULL; + +ALTER TABLE config.config_notification + ADD COLUMN IF NOT EXISTS signing_key text NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS previous_signing_key text NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS previous_signing_key_until timestamptz; + +ALTER TABLE config.config_notification_routes + ADD COLUMN IF NOT EXISTS signing_key text NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS previous_signing_key text NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS previous_signing_key_until timestamptz, + ADD COLUMN IF NOT EXISTS fallback_route_id integer; + +DO $do$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_fallback' + AND conrelid = 'config.config_notification_routes'::regclass) THEN + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_fallback CHECK (fallback_route_id IS NULL OR fallback_route_id <> route_id); + END IF; +END $do$; + +ALTER TABLE collect.procedure_stats + ADD COLUMN IF NOT EXISTS module_modify_date timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (193, 'phase-c-store', now()::timestamp); +-- ===BATCH=== V194 query-tag-sightings-database + +CREATE UNIQUE INDEX IF NOT EXISTS ux_query_tag_sightings_key_db + ON collect.query_tag_sightings (server_id, key_kind, key, COALESCE(application_name, ''), COALESCE(login_name, ''), COALESCE(host_name, ''), COALESCE(database_name, '')); +DROP INDEX IF EXISTS collect.ux_query_tag_sightings_key; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (194, 'query-tag-sightings-database', now()::timestamp); +-- ===BATCH=== V195 query-store-forced-plans + +CREATE TABLE IF NOT EXISTS collect.query_store_forced_plans ( + collection_id bigint NOT NULL, + collection_time timestamp NOT NULL, + server_id integer NOT NULL, + server_name text NOT NULL, + database_name text, + plan_id bigint, + query_id bigint, + query_plan_hash text, + plan_forcing_type text, + force_failure_count bigint, + last_force_failure_reason text, + last_execution_time timestamp, + last_compile_start_time timestamp +); + +CREATE INDEX IF NOT EXISTS idx_query_store_forced_plans_time ON collect.query_store_forced_plans(server_id, collection_time); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (195, 'query-store-forced-plans', now()::timestamp); +-- ===BATCH=== V196 level-3-server-action-switches + +DO $do$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_config_notification_routes_agent' + AND conrelid = 'config.config_notification_routes'::regclass + AND pg_get_constraintdef(oid) !~ 'ARRAY\[0, 1, 2, 3\]') THEN + ALTER TABLE config.config_notification_routes DROP CONSTRAINT ck_config_notification_routes_agent; + ALTER TABLE config.config_notification_routes + ADD CONSTRAINT ck_config_notification_routes_agent CHECK ( + (agent_level IS NULL OR agent_level IN (0, 1, 2, 3)) + AND agent_max_per_hour BETWEEN 1 AND 60 + AND agent_max_per_day BETWEEN 1 AND 500 + AND agent_lease_minutes BETWEEN 5 AND 120 + AND agent_expiry_minutes BETWEEN 15 AND 1440); + END IF; + + IF EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_investigation_requests_autonomy' + AND conrelid = 'config.investigation_requests'::regclass + AND pg_get_constraintdef(oid) !~ 'ARRAY\[1, 2, 3\]') THEN + ALTER TABLE config.investigation_requests DROP CONSTRAINT ck_investigation_requests_autonomy; + ALTER TABLE config.investigation_requests + ADD CONSTRAINT ck_investigation_requests_autonomy CHECK (autonomy_level IN (1, 2, 3)); + END IF; +END $do$; + +CREATE TABLE IF NOT EXISTS config.config_server_actions +( + server_id integer NOT NULL, + action text NOT NULL, + enabled boolean NOT NULL DEFAULT false, + set_by text NOT NULL, + updated_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT pk_config_server_actions PRIMARY KEY (server_id, action), + CONSTRAINT fk_config_server_actions_server FOREIGN KEY (server_id) + REFERENCES config.config_monitored_servers (server_id) ON DELETE CASCADE, + CONSTRAINT ck_config_server_actions_action CHECK (action IN ('force_plan', 'evict_plan', 'kill_session')), + CONSTRAINT ck_config_server_actions_set_by CHECK (btrim(set_by) <> '') +); + +DROP TRIGGER IF EXISTS trg_bump_server_actions ON config.config_server_actions; +CREATE TRIGGER trg_bump_server_actions + AFTER INSERT OR UPDATE OR DELETE ON config.config_server_actions + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (196, 'level-3-server-action-switches', now()::timestamp); +-- ===BATCH=== V197 plan-force-checks + +ALTER TABLE config.investigation_requests + ADD COLUMN IF NOT EXISTS force_check_of bigint, + ADD COLUMN IF NOT EXISTS force_check_no smallint; + +DO $do$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conname = 'ck_investigation_requests_force_check' + AND conrelid = 'config.investigation_requests'::regclass) THEN + ALTER TABLE config.investigation_requests + ADD CONSTRAINT ck_investigation_requests_force_check CHECK ( + (force_check_of IS NULL AND force_check_no IS NULL) + OR (force_check_of IS NOT NULL AND force_check_no BETWEEN 1 AND 26)); + END IF; +END $do$; + +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_requests_force_check + ON config.investigation_requests (force_check_of, force_check_no) + WHERE force_check_of IS NOT NULL; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (197, 'plan-force-checks', now()::timestamp); +-- ===BATCH=== V198 pseudonym-key + +CREATE TABLE IF NOT EXISTS config.pseudonym_key +( + id smallint NOT NULL, + key bytea NOT NULL, + created_at timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + CONSTRAINT pk_pseudonym_key PRIMARY KEY (id), + CONSTRAINT ck_pseudonym_key_single_row CHECK (id = 1), + CONSTRAINT ck_pseudonym_key_length CHECK (octet_length(key) = 32) +); + +REVOKE ALL ON config.pseudonym_key FROM PUBLIC; + +DO $do$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles AS r WHERE r.rolname = 'admin') THEN + REVOKE ALL ON config.pseudonym_key FROM admin; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles AS r WHERE r.rolname = 'viewer') THEN + REVOKE ALL ON config.pseudonym_key FROM viewer; + END IF; + IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles AS r WHERE r.rolname = 'mcp') THEN + REVOKE ALL ON config.pseudonym_key FROM mcp; + END IF; +END +$do$; + +DROP TRIGGER IF EXISTS trg_pseudonym_key_owner_only_row ON config.pseudonym_key; +CREATE TRIGGER trg_pseudonym_key_owner_only_row + BEFORE INSERT OR UPDATE OR DELETE ON config.pseudonym_key + FOR EACH ROW EXECUTE FUNCTION config.password_key_owner_only(); +DROP TRIGGER IF EXISTS trg_pseudonym_key_owner_only_truncate ON config.pseudonym_key; +CREATE TRIGGER trg_pseudonym_key_owner_only_truncate + BEFORE TRUNCATE ON config.pseudonym_key + FOR EACH STATEMENT EXECUTE FUNCTION config.password_key_owner_only(); +ALTER TABLE config.pseudonym_key ENABLE ALWAYS TRIGGER trg_pseudonym_key_owner_only_row; +ALTER TABLE config.pseudonym_key ENABLE ALWAYS TRIGGER trg_pseudonym_key_owner_only_truncate; + +INSERT INTO config.pseudonym_key (id, key) +VALUES (1, pg_catalog.sha256(pg_catalog.decode( + pg_catalog.replace(pg_catalog.gen_random_uuid()::text || pg_catalog.gen_random_uuid()::text, '-', ''), 'hex'))) +ON CONFLICT (id) DO NOTHING; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (198, 'pseudonym-key', now()::timestamp); +-- ===BATCH=== V199 blocking-head-evidence + +ALTER TABLE collect.dmv_blocking_snapshots ADD COLUMN IF NOT EXISTS blocking_login_time timestamp; +ALTER TABLE collect.dmv_blocking_snapshots ADD COLUMN IF NOT EXISTS blocking_last_request_end_time timestamp; +ALTER TABLE collect.dmv_blocking_snapshots ADD COLUMN IF NOT EXISTS blocking_open_transaction_count integer; +ALTER TABLE collect.dmv_blocking_snapshots ADD COLUMN IF NOT EXISTS blocking_tran_log_bytes_used bigint; +CREATE OR REPLACE VIEW v_dmv_blocking_snapshots AS SELECT * FROM dmv_blocking_snapshots; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (199, 'blocking-head-evidence', now()::timestamp); +-- ===BATCH=== V200 excluded-volumes + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS excluded_volumes text[] NOT NULL DEFAULT '{}'::text[]; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (200, 'excluded-volumes', now()::timestamp); +-- ===BATCH=== V201 forced-plan-variants-and-guides + +ALTER TABLE collect.query_store_forced_plans ADD COLUMN IF NOT EXISTS variant_plan_ids text; +ALTER TABLE collect.query_store_forced_plans ADD COLUMN IF NOT EXISTS plan_guide_name text; +ALTER TABLE collect.query_store_forced_plans ADD COLUMN IF NOT EXISTS plan_guide_enabled boolean; +ALTER TABLE collect.query_store_forced_plans ADD COLUMN IF NOT EXISTS plan_guide_scope text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (201, 'forced-plan-variants-and-guides', now()::timestamp); +-- ===BATCH=== V202 ag-primary-replica + +ALTER TABLE collect.ag_replica_states ADD COLUMN IF NOT EXISTS primary_replica text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (202, 'ag-primary-replica', now()::timestamp); +-- ===BATCH=== V203 hypothetical-index-login + +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS hypothetical_index_username text; +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS hypothetical_index_encrypted_password text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (203, 'hypothetical-index-login', now()::timestamp); +-- ===BATCH=== V204 custom-view-folders + +ALTER TABLE config.custom_views ADD COLUMN IF NOT EXISTS folder text; +ALTER TABLE config.custom_views ADD COLUMN IF NOT EXISTS personal boolean NOT NULL DEFAULT false; +ALTER TABLE config.custom_views ADD COLUMN IF NOT EXISTS created_by text; +ALTER TABLE config.custom_views ADD COLUMN IF NOT EXISTS owner_key text; + +DO $$ +DECLARE + unique_name text; +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conrelid = 'config.custom_views'::regclass AND conname = 'ck_custom_views_folder') + THEN + ALTER TABLE config.custom_views ADD CONSTRAINT ck_custom_views_folder CHECK ( + folder IS NULL + OR (folder = btrim(folder) AND folder <> '' AND char_length(folder) <= 100 AND folder !~ '[--Ÿ]')); + END IF; + + IF NOT EXISTS (SELECT 1 FROM pg_constraint + WHERE conrelid = 'config.custom_views'::regclass AND conname = 'ck_custom_views_personal_owner') + THEN + ALTER TABLE config.custom_views ADD CONSTRAINT ck_custom_views_personal_owner CHECK (NOT personal OR owner_key IS NOT NULL); + END IF; + + /* V31's UNIQUE (name), found by the one column it covers so a renamed constraint is dropped too. */ + FOR unique_name IN + SELECT con.conname + FROM pg_constraint con + WHERE con.conrelid = 'config.custom_views'::regclass + AND con.contype = 'u' + AND con.conkey = ARRAY[(SELECT a.attnum FROM pg_attribute a + WHERE a.attrelid = 'config.custom_views'::regclass AND a.attname = 'name')] + LOOP + EXECUTE format('ALTER TABLE config.custom_views DROP CONSTRAINT %I', unique_name); + END LOOP; +END $$; + +CREATE UNIQUE INDEX IF NOT EXISTS ux_custom_views_shared_name ON config.custom_views ((COALESCE(folder, '')), name) WHERE NOT personal; +CREATE UNIQUE INDEX IF NOT EXISTS ux_custom_views_personal_name ON config.custom_views (owner_key, name) WHERE personal; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (204, 'custom-view-folders', now()::timestamp); +-- ===BATCH=== V205 custom-alert-rule-expiry + +ALTER TABLE config.custom_alert_rules ADD COLUMN IF NOT EXISTS expires_at_utc timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (205, 'custom-alert-rule-expiry', now()::timestamp); +-- ===BATCH=== V206 collector-enabled-inherit + +ALTER TABLE config.config_collector_schedules ALTER COLUMN enabled DROP NOT NULL; + +DELETE FROM config.config_collector_schedules +WHERE ctid IN +( + SELECT d.row_id + FROM + ( + SELECT + s.ctid AS row_id, + row_number() OVER ( + PARTITION BY s.server_id, lower(s.collector_name) + ORDER BY (s.collector_name = lower(s.collector_name)) DESC, s.collector_name) AS keep_rank + FROM config.config_collector_schedules AS s + ) AS d + WHERE d.keep_rank > 1 +); +UPDATE config.config_collector_schedules SET collector_name = lower(collector_name) WHERE collector_name <> lower(collector_name); +DELETE FROM config.config_collector_schedules WHERE collector_name !~ '^[a-z0-9_]{1,64}$'; +UPDATE config.config_collector_schedules SET frequency_minutes = 525600 WHERE frequency_minutes > 525600; +UPDATE config.config_collector_schedules SET retention_days = 3650 WHERE retention_days > 3650; + +DO $limits$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conrelid = 'config.config_collector_schedules'::regclass AND conname = 'ck_config_collector_schedules_name') THEN + ALTER TABLE config.config_collector_schedules + ADD CONSTRAINT ck_config_collector_schedules_name CHECK (collector_name ~ '^[a-z0-9_]{1,64}$') NOT VALID; + END IF; + IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conrelid = 'config.config_collector_schedules'::regclass AND conname = 'ck_config_collector_schedules_frequency_cap') THEN + ALTER TABLE config.config_collector_schedules + ADD CONSTRAINT ck_config_collector_schedules_frequency_cap CHECK (frequency_minutes <= 525600) NOT VALID; + END IF; + IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conrelid = 'config.config_collector_schedules'::regclass AND conname = 'ck_config_collector_schedules_retention_cap') THEN + ALTER TABLE config.config_collector_schedules + ADD CONSTRAINT ck_config_collector_schedules_retention_cap CHECK (retention_days <= 3650) NOT VALID; + END IF; +END +$limits$; + +CREATE OR REPLACE FUNCTION config.config_clear_unregistered_schedules() RETURNS trigger +LANGUAGE plpgsql +SECURITY DEFINER +SET search_path = pg_catalog, pg_temp +AS $clear$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM config.config_monitored_servers AS m WHERE m.server_id = NEW.server_id) + AND NOT EXISTS (SELECT 1 FROM collect.servers AS o WHERE o.server_id = NEW.server_id) THEN + DELETE FROM config.config_collector_schedules WHERE server_id = NEW.server_id; + END IF; + RETURN NEW; +END; +$clear$; +REVOKE ALL ON FUNCTION config.config_clear_unregistered_schedules() FROM PUBLIC; +DROP TRIGGER IF EXISTS trg_clear_unregistered_schedules ON config.config_monitored_servers; +CREATE TRIGGER trg_clear_unregistered_schedules + BEFORE INSERT ON config.config_monitored_servers + FOR EACH ROW EXECUTE FUNCTION config.config_clear_unregistered_schedules(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (206, 'collector-enabled-inherit', now()::timestamp); +-- ===BATCH=== V207 change-watches + +ALTER TABLE config.investigation_requests ADD COLUMN IF NOT EXISTS trigger_kind text NOT NULL DEFAULT 'alert'; + +CREATE TABLE IF NOT EXISTS config.change_watches +( + watch_id uuid PRIMARY KEY, + server_id integer NOT NULL, + server_name text NOT NULL, + opened_at timestamptz NOT NULL, + first_change_at timestamptz NOT NULL, + last_change_at timestamptz NOT NULL, + window_ends_at timestamptz NOT NULL, + state text NOT NULL DEFAULT 'open', + closed_at timestamptz, + result text, + request_id uuid, + result_json text, + claimed_at timestamptz, + attempts smallint NOT NULL DEFAULT 0, + CONSTRAINT ck_change_watches_state CHECK (state IN ('open', 'evaluating', 'closed', 'failed')) +); + +/* A store that took an earlier draft of this rung has the table without the claim column and with the two-state check. */ +ALTER TABLE config.change_watches ADD COLUMN IF NOT EXISTS claimed_at timestamptz; +ALTER TABLE config.change_watches ADD COLUMN IF NOT EXISTS attempts smallint NOT NULL DEFAULT 0; +ALTER TABLE config.change_watches DROP CONSTRAINT IF EXISTS ck_change_watches_state; +ALTER TABLE config.change_watches ADD CONSTRAINT ck_change_watches_state CHECK (state IN ('open', 'evaluating', 'closed', 'failed')); + +/* One request per watch: the request's first dedup key is the watch id, so a retry, a crash between the open and the close, or a second + instance cannot open a second one (the loser's insert fails and it reads the winner's). */ +CREATE UNIQUE INDEX IF NOT EXISTS uq_investigation_requests_change_watch + ON config.investigation_requests (first_dedup_key) WHERE trigger_kind = 'change_watch'; + +CREATE UNIQUE INDEX IF NOT EXISTS uq_change_watches_open ON config.change_watches (server_id) WHERE state = 'open'; +CREATE INDEX IF NOT EXISTS ix_change_watches_server_opened ON config.change_watches (server_id, opened_at); + +CREATE TABLE IF NOT EXISTS config.change_watch_changes +( + server_id integer NOT NULL, + change_key text NOT NULL, + watch_id uuid NOT NULL REFERENCES config.change_watches (watch_id) ON DELETE CASCADE, + change_kind text NOT NULL, + change_time timestamptz NOT NULL, + description text NOT NULL, + database_name text, + query_id bigint, + plan_id bigint, + PRIMARY KEY (server_id, change_key) +); + +ALTER TABLE config.change_watch_changes ADD COLUMN IF NOT EXISTS plan_id bigint; + +CREATE INDEX IF NOT EXISTS ix_change_watch_changes_watch ON config.change_watch_changes (watch_id); + +/* The high-water mark of change detection, per server and per source: detection reads only snapshots newer than it, so a tick costs the + new rows and not the history. A server with no mark yet gets every mark set to now and opens nothing for what is already stored. */ +CREATE TABLE IF NOT EXISTS config.change_watch_marks +( + server_id integer NOT NULL, + source text NOT NULL, + mark timestamptz NOT NULL, + PRIMARY KEY (server_id, source) +); + +/* #6239 round 3, L5: plan detection finds a database's previous forced-plan capture by its marker row (plan_id IS NULL), one index seek per new capture, + and no longer reads a day of forced-plan rows per server per pass. A few rows per database per pass, so the build is a read of a small plain table. */ +CREATE INDEX IF NOT EXISTS idx_query_store_forced_plans_markers + ON collect.query_store_forced_plans (server_id, database_name, collection_time) WHERE plan_id IS NULL; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (207, 'change-watches', now()::timestamp); +-- ===BATCH=== V208 mute-rule-starts-at + +ALTER TABLE config.config_mute_rules ADD COLUMN IF NOT EXISTS starts_at_utc timestamp; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (208, 'mute-rule-starts-at', now()::timestamp); +-- ===BATCH=== V209 query-store-fetch-top-n + +ALTER TABLE config.config_service ADD COLUMN IF NOT EXISTS query_store_fetch_top_n integer NOT NULL DEFAULT 100; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (209, 'query-store-fetch-top-n', now()::timestamp); +-- ===BATCH=== V210 mcp-agent-route-tag-guard + +CREATE OR REPLACE FUNCTION config.agent_route_tag_guard() +RETURNS trigger +LANGUAGE plpgsql +SECURITY DEFINER +SET search_path = pg_catalog, pg_temp +AS $guard$ +DECLARE + v_route integer; + v_up integer[]; + v_down integer[]; +BEGIN + IF session_user::text IS DISTINCT FROM 'mcp' + AND COALESCE(pg_catalog.current_setting('darling.surface', true), '') <> 'mcp' THEN + RETURN CASE WHEN TG_OP = 'DELETE' THEN OLD ELSE NEW END; + END IF; + + v_up := ARRAY[]::integer[]; + v_down := ARRAY[]::integer[]; + IF TG_TABLE_NAME = 'server_tag_map' THEN + IF TG_OP IN ('INSERT', 'UPDATE') THEN + v_up := v_up || NEW.tag_id; + END IF; + IF TG_OP IN ('DELETE', 'UPDATE') THEN + v_up := v_up || OLD.tag_id; + END IF; + ELSIF TG_OP = 'DELETE' THEN + v_down := ARRAY[OLD.id]; + IF OLD.parent_id IS NOT NULL THEN + v_up := ARRAY[OLD.parent_id]; + END IF; + ELSIF NEW.parent_id IS DISTINCT FROM OLD.parent_id THEN + v_down := ARRAY[OLD.id]; + IF OLD.parent_id IS NOT NULL THEN + v_up := v_up || OLD.parent_id; + END IF; + IF NEW.parent_id IS NOT NULL THEN + v_up := v_up || NEW.parent_id; + END IF; + END IF; + + IF cardinality(v_up) + cardinality(v_down) > 0 THEN + WITH RECURSIVE above(id, parent_id) AS ( + SELECT t.id, t.parent_id FROM config.server_tags AS t WHERE t.id = ANY(v_up) + UNION + SELECT p.id, p.parent_id FROM config.server_tags AS p JOIN above AS a ON p.id = a.parent_id), + below(id) AS ( + SELECT t.id FROM config.server_tags AS t WHERE t.id = ANY(v_down) + UNION + SELECT c.id FROM config.server_tags AS c JOIN below AS b ON c.parent_id = b.id) + SELECT r.route_id INTO v_route + FROM config.config_notification_routes AS r + WHERE r.agent_level IS NOT NULL + AND (r.scope_tag_id IN (SELECT a.id FROM above AS a) OR r.scope_tag_id IN (SELECT b.id FROM below AS b)) + ORDER BY r.route_id + LIMIT 1; + IF v_route IS NOT NULL THEN + RAISE EXCEPTION 'Route % has an agent setting (Off included) and its tag is this tag, or is above or below it, so changes to which servers it covers are made in the Viewer or on the web dashboard, not over MCP.', v_route + USING ERRCODE = 'DL403'; + END IF; + END IF; + + RETURN CASE WHEN TG_OP = 'DELETE' THEN OLD ELSE NEW END; +END +$guard$; +REVOKE ALL ON FUNCTION config.agent_route_tag_guard() FROM PUBLIC; + +DROP TRIGGER IF EXISTS trg_agent_route_tag_guard ON config.server_tag_map; +CREATE TRIGGER trg_agent_route_tag_guard + BEFORE INSERT OR UPDATE OR DELETE ON config.server_tag_map + FOR EACH ROW EXECUTE FUNCTION config.agent_route_tag_guard(); +ALTER TABLE config.server_tag_map ENABLE ALWAYS TRIGGER trg_agent_route_tag_guard; + +DROP TRIGGER IF EXISTS trg_agent_route_tag_guard ON config.server_tags; +CREATE TRIGGER trg_agent_route_tag_guard + BEFORE UPDATE OR DELETE ON config.server_tags + FOR EACH ROW EXECUTE FUNCTION config.agent_route_tag_guard(); +ALTER TABLE config.server_tags ENABLE ALWAYS TRIGGER trg_agent_route_tag_guard; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (210, 'mcp-agent-route-tag-guard', now()::timestamp); +-- ===BATCH=== V211 client-timeouts-relative-bars + +ALTER TABLE config.config_alert_settings + ADD COLUMN IF NOT EXISTS client_timeouts_warning_multiple integer NOT NULL DEFAULT 3, + ADD COLUMN IF NOT EXISTS client_timeouts_critical_multiple integer NOT NULL DEFAULT 10; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (211, 'client-timeouts-relative-bars', now()::timestamp); +-- ===BATCH=== V212 server-machine-identity + +ALTER TABLE collect.servers + ADD COLUMN IF NOT EXISTS machine_identity text; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (212, 'server-machine-identity', now()::timestamp); +-- ===BATCH=== V213 query-store-replica + +ALTER TABLE config.config_monitored_servers ADD COLUMN IF NOT EXISTS query_store_replica text; +ALTER TABLE collect.collection_log ADD COLUMN IF NOT EXISTS read_source text; + +/* The log lives in the collect schema, and its passthrough view freezes its column list at CREATE (the V80 lesson), so every read + of the log (the MCP tools, the web page, the Viewer) would never see read_source without this. Appending is the one alteration + CREATE OR REPLACE VIEW permits, which is exactly what an ADD COLUMN produces. */ +CREATE OR REPLACE VIEW collect.v_collection_log AS SELECT * FROM collect.collection_log; +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (213, 'query-store-replica', now()::timestamp); +-- ===BATCH=== V214 known-patterns + +CREATE TABLE IF NOT EXISTS config.config_known_patterns +( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + server_id integer, + metric_name text, + time_of_day time, + time_zone text, + window_minutes integer NOT NULL DEFAULT 30, + note text NOT NULL, + created_by text, + created_at_utc timestamp NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'), + expires_at_utc timestamp, + updated_by text, + updated_at_utc timestamp, + CONSTRAINT ck_known_patterns_note CHECK (char_length(note) BETWEEN 1 AND 500 AND btrim(note, E' +') <> ''), + CONSTRAINT ck_known_patterns_window CHECK (window_minutes BETWEEN 0 AND 720), + CONSTRAINT ck_known_patterns_time_of_day CHECK (time_of_day < '24:00'), + CONSTRAINT ck_known_patterns_expires CHECK (expires_at_utc IS NULL OR (isfinite(expires_at_utc) AND expires_at_utc < '10000-01-01')), + CONSTRAINT ck_known_patterns_time_zone CHECK (time_zone IS NULL OR (char_length(time_zone) <= 64 AND time_zone ~ '^[A-Za-z0-9_+-]+(/[A-Za-z0-9_+-]+)*$')), + CONSTRAINT ck_known_patterns_metric CHECK (char_length(metric_name) <= 128), + CONSTRAINT ck_known_patterns_created_by CHECK (char_length(created_by) <= 256), + CONSTRAINT ck_known_patterns_updated_by CHECK (char_length(updated_by) <= 256) +); + +DROP TRIGGER IF EXISTS trg_bump_known_patterns ON config.config_known_patterns; +CREATE TRIGGER trg_bump_known_patterns + AFTER INSERT OR UPDATE OR DELETE ON config.config_known_patterns + FOR EACH STATEMENT EXECUTE FUNCTION config.config_bump_version(); +INSERT INTO darling_schema_version (version, name, applied_at) VALUES (214, 'known-patterns', now()::timestamp); diff --git a/Directory.Build.props b/Directory.Build.props index e7d184cc48..4fc975a93b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,7 +15,7 @@ agree with the XML read, so the ordering is enforced rather than remembered. --> - 3.11.0 + 3.12.0 false diff --git a/README.md b/README.md index 1d0630b861..944510aa22 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ It supports SQL Server 2016 SP2 to 2025. SQL Server 2017 needs CU3 or later. It - **Lite** is a single desktop app that monitors your servers remotely, on demand. Nothing is installed on your server. It stores data in local DuckDB and Parquet files. - **Darling** is a service on Windows or Linux that collects 24/7 into a central PostgreSQL store. The Windows viewer and the web dashboard read that store from any seat. -Both editions can hand an alert to an AI agent that you run, and Lite lets the agent read and report. Darling can also let it change alert settings (mutes, custom alert rules and thresholds). On a server, it can force or unforce a Query Store plan, evict a cached plan or kill a session. Each of these has its own switch per server, and all are off until you turn them on. Darling records every change, and a person can undo alert-setting changes and plan forces but not a plan eviction or a session kill. [Agent dispatch](docs/darling-agent-dispatch.md) explains the levels. +Both editions can hand an alert to an AI agent that you run, and Lite lets the agent read and report. Darling can also let it change alert settings (mutes, custom alert rules and thresholds). On a server, it can force or unforce a Query Store plan or evict a cached plan. It can recompile a module, create or drop a plan guide, or kill a session. Each of these has its own switch per server, and all are off until you turn them on. Darling records every change. A person can undo alert-setting changes, plan forces and plan guide changes. A plan eviction, a recompile or a session kill cannot be undone. [Agent dispatch](docs/darling-agent-dispatch.md) explains the levels. The Dashboard edition is deprecated. Existing installs keep working, but we recommend Lite or Darling for new deployments. [Choosing an edition](docs/editions.md) compares all three. @@ -46,9 +46,9 @@ Before you upgrade an older install with `Setup.exe`, read the warning in the [L 1. Download `PerformanceMonitorDarling-.zip` and `SHA256SUMS.txt` from the [latest release](https://github.com/erikdarlingdata/PerformanceMonitor/releases/latest). Check the zip hash against `SHA256SUMS.txt`. The zip carries its own .NET runtime, so there is nothing to install first. 2. Extract the zip to `C:\Program Files\PerformanceMonitorDarling`. Do not use your Desktop, Downloads, or any folder under `C:\Users\`. The service runs as a virtual account that cannot read a user profile ([why](docs/darling/install.md#step-3-extract-to-a-machine-scoped-path)). -3. Copy `darling.sample.json` to `darling.json` and add one server. `darling.json` is only a seed. The service reads it on the first start, and after that the store is the authority. If you edit the file later to add a server, nothing changes. Add servers in the viewer instead ([why](docs/darling/install.md#darlingjson-is-only-a-seed)). -4. From an elevated PowerShell in the install folder, run `.\install-darling.ps1`. It installs the Windows service and creates a **Darling Viewer** shortcut. -5. Wait about two minutes for the first start, then open **Darling Viewer**. It opens on the fleet. +3. Double-click `Install-Darling.cmd` in the install folder. It asks Windows for administrator rights and runs `install-darling.ps1`. You can also run `.\install-darling.ps1` from an elevated PowerShell. It installs the Windows service and creates a **Darling Viewer** shortcut. With no `darling.json` it writes a minimal one, and the service starts with no monitored servers. +4. Wait about two minutes for the first start, then open **Darling Viewer**. It opens on the fleet. +5. Add your first server in the viewer. `darling.json` is only a seed. The service reads it on its first start, so a server added to the file later is ignored ([why](docs/darling/install.md#darlingjson-is-only-a-seed)). 6. The service log is in `%ProgramData%\PerformanceMonitorDarling\logs`. [Install Darling](docs/darling/install.md) gives each step with the log line or screen that proves it worked. To upgrade, run `upgrade-darling.ps1`. To remove the service, run `uninstall-darling.ps1`. Both are in the install folder. For Linux and the web dashboard, read the [Darling quick start](docs/darling-quick-start.md). The [Darling operator guide](Darling/README.md) is the configuration reference. diff --git a/docs/changelog/3.12.md b/docs/changelog/3.12.md new file mode 100644 index 0000000000..63a6c6f673 --- /dev/null +++ b/docs/changelog/3.12.md @@ -0,0 +1,607 @@ +# PerformanceMonitor 3.12.0 + +The full changelog entries for 3.12.0. [CHANGELOG.md](../../CHANGELOG.md) carries the +compacted index for every version, this one included, and is where `[Unreleased]` is written. + +## [3.12.0] - 2026-10-30 + +### Important + +- **Upgrading from 3.11 runs the Darling store migrations V215 through V229 on the service's first start** - the store schema goes from 214 to 229. Every step adds something, and none rewrites a large table or needs an offline window. The new tables hold the Query Store hints (V217), the keys of the monitor's own Query Store statements (V219), the narrow hourly and daily Query Store data for the query tag roll-up (V221), and the SQL Server Agent alerts, the database protection ages and the identity capacity (V222, V223, V224). The new indexes are six on the investigation tables (V215) and one for the Job History statistics (V220). The new columns are two Amazon RDS flags on the server registry (V225, V226), a server tag scope on threshold overrides (V227), four blocking band columns on the alert settings row (V228), and the severity filter on notification routes with two supporting columns (V229). V218 widens a check to allow the recompile and plan guide server actions, V219 also adds two triggers on the Query Store text table, and V216 changes the Client Timeouts default (next item). The V220 index built in under a second on a copy of a production store, because a compressed chunk holds no rows in it. Two steps leave work for after the first start. The V219 key backfill runs in the background and took 157 seconds on a copy of a large store. The hourly builder fills the V221 tables, newest hours first, so until it catches up a fleet query tag read says how many hours it left out. An older build ignores all of these, and the rollback notes in `docs/darling/admin.md` list what each leaves behind. + +- **The Client Timeouts alert is on after the upgrade, in Darling and Lite** ([#5736]) - The alert shipped off because its bars were not checked against real data. They now follow each server's own baseline, and a 7 day replay over 42 servers paged twice. Store migration V216 sets the Darling default to on. It also moves the stored off value to on, because that value was the old default and a store cannot tell it from a choice. Lite does the same once, with a marker in settings.json. If you had it off on purpose, switch it off again once after the upgrade. + +- **Lite's DuckDB schema stays at version 78** - There is no Lite schema migration in this release. Lite starts as it did on 3.11, and nothing needs to be done. + +- **Self-managed stores: re-run `provision-roles.sql` after upgrading** ([#6542], [#6395], [#6386], [#6389], [#6392], [#6393], [#6394], [#6396], [#6397], [#6398], [#6400], [#6401], [#6454], [#6455], [#6569], [#6928], [#6743]) - Run `Darling/tools/provision-roles.sql` again after the upgrade. The script gained the store functions and grants behind the new MCP write tools and web buttons. They cover a route's agent settings, the default notification channels, webhook signing keys, the service flags, agent actions on and off, database state expectations, a collector's database scope, known patterns, agent notes and closing an investigation request. They also cover the Analyze now and live Active Queries requests, the host change refusal text, and the severity filter column on notification routes. Until the script is re-run, the tools that need a missing function or grant fail. The route, signing key and default channel tools say in one sentence to re-run it. Collection and reads keep working. The compose store and managed provisioning do all of this on their own. + +- **New msdb grants for existing monitoring logins** ([#6874], [#6873]) - This release adds two Darling collectors that read three msdb tables. A monitoring login set up for an earlier release does not have these grants. Until you add them, those collectors show as "no permission" in Collection Health. Run these on each SQL Server target, in the msdb database, with your monitoring login in place of `[YourLogin]`. `GRANT SELECT ON dbo.sysalerts TO [YourLogin]` covers the SQL Agent alert definitions and counters. `GRANT SELECT ON dbo.sysnotifications TO [YourLogin]` covers the operators each Agent alert notifies. `GRANT SELECT ON dbo.backupset TO [YourLogin]` covers the last full and log backup per database. The grants are optional, and the rest of collection continues as normal without them. Lite does not use these collectors. The Agent alerts collector does not run on Amazon RDS, Azure SQL Database or Azure SQL Managed Instance. Those servers do not need the first two grants. See `docs/permissions.md` for the full list. + +- **The Darling web dashboard and MCP server, and Lite's MCP server, need a token once turned on** ([#6507], [#6557]) - Before, a loopback-only start with no token served every request with no credential. Now the web dashboard and MCP server do not start without a token, and they log one Critical line that names the settings to add. To keep the old tokenless loopback behaviour, with reads only, set `web.allowTokenlessLoopback` or `mcp.allowTokenlessLoopback` in darling.json. Lite's MCP server now answers 401 to any request without a valid bearer token. Lite makes its own token the first time the server starts. The Settings tab has a Copy MCP config button, so an MCP client that sent no token needs the new config. + +- **Web dashboard Admin writes stay off after an upgrade until `web.allowAdminWrites` is true** ([#6600], [#6745]) - A missing key means false. Without the key the web Admin pages still list. These writes are refused: arming server-action switches, changing notification routes, webhook URLs and threshold overrides, and undoing agent changes. That is how 3.11 behaved. New installs from the MSI and the install scripts write `"allowAdminWrites": true`. To turn it on for an upgraded install, set it to true in darling.json and restart the service. + +- **Adding servers is stricter** ([#6583], [#6752]) - A SQL Server entry's port field was stored but never used to connect. `add_servers`, the web add route and `--add-server` now refuse a non-zero port on a SQL Server target. They say to write it in the host as `host,port`. `--validate-config` warns about each existing entry that has a port. The web add and edit routes also refuse Windows sign-in over an unverified certificate unless `web.allowWindowsAuthOverUnverifiedTls` is true, as the MCP tools already did. + + +### Added + +- **Notification routes can match on alert severity** ([#6928]) - A route now has a severities setting of both (the default), critical or warning (store migration V229). Existing routes keep their effect. A warning route also takes every alert that is not Critical. A resolution goes to the channels the fire went to, and a Warning that climbs to Critical is sent again as Critical. The agent-action gate also resolves each alert's route at that alert's severity. + +- **Blocking colours follow settable blocking bands** ([#6927]) - The blocking colour on the Fleet Overview, the Overview tab and the Daily Health Calendar came from fixed limits. Warning started at 5 reports an hour or a 10 second block, and Critical at 20 reports or 60 seconds. A tuned blocking alert still showed red. Four settings now hold the bands (store migration V228), with those limits as defaults. Set them in the Darling viewer Settings window or with update_alert_settings. The fleet totals tiles use the worst band among the servers, and Lite keeps the fixed limits. + +- **Alert threshold overrides can be set for a server tag** ([#6926]) - Store migration V227 adds the tag scope. The order is database, server, tag, then global. A tag covers its servers and the tags below it, and the deepest tag wins. The set_alert_threshold_override tool takes a tag in place of server_name. The web Admin tab and the Darling viewer's Threshold Overrides window list and edit tag rows. + +- **The Darling grant script has an Amazon RDS form** ([#6889]) - Amazon RDS for SQL Server has no sysadmin and refuses CONNECT ANY DATABASE, ALTER SETTINGS and eight msdb grants to its master user. The command --grant-script --rds prints a script that runs as the master user and leaves those grants out. It creates the login's user in each current user database. Job History in Lite and Darling no longer fails every cycle on RDS when the login cannot read syscategories. A collector run that skips a database because the login has no user in it now says so in its collection log note. The connection test warns with the count. + +- **Darling warns before an identity column runs out of values** ([#6875]) - A new collector reads sys.identity_columns every six hours in each user database (store migration V224). It stores the top 20 columns above 10 percent used plus a marker row for each scanned database. The get_identity_capacity tool, web panels, a Darling viewer tab and a fleet card chip show percent used and days to exhaustion. A new Identity Capacity alert is off by default and goes Warning at 70 percent used and Critical at 90. The collector needs VIEW ANY DEFINITION, which the grant script already holds. A pass that runs past 5 minutes stops, and the next pass resumes where it left off. + +- **Darling checks the SQL Server Agent alert setup** ([#6874], [#6894], [#6908]) - A new agent_alerts collector reads msdb.dbo.sysalerts and the operators each alert notifies every 15 minutes on SQL Server. Grant SELECT on msdb.dbo.sysalerts and msdb.dbo.sysnotifications to the monitoring login. The get_agent_alerts tool, the web Configuration tab and a new Agent Alerts tab in the Darling viewer report the gaps. A gap is a missing alert for severities 19 to 25 or errors 823 to 825, or an alert that has no operator. A new Agent Alert Gaps alert is off by default. Azure SQL Database, Managed Instance and Amazon RDS do not run the collector, and get_agent_alerts and get_running_jobs answer not collected there (store migrations V222 and V225). + +- **Darling watches backups and CHECKDB per database** ([#6873], [#6902], [#6946]) - A new hourly collector stores the last good CHECKDB and the last full and log backup of every database. Grant SELECT on msdb.dbo.backupset to the monitoring login, or the collector records a permissions skip. The RDS form of the grant script leaves it out. The get_database_protection tool, two web Health Checks panels and a Database Protection tab in the Darling viewer show each age. They flag full backups older than 7 days, log backups older than 60 minutes and CHECKDB older than 14 days. Three new alerts are off by default: Backup Overdue, Log Backup Overdue and CHECKDB Overdue (store migration V223). + +- **Darling reads PostgreSQL server logs written in a named local log_timezone** ([#6866]) - Darling used to refuse the whole log read when the target's log_timezone was a named local zone such as CET, Europe/Berlin or America/Los_Angeles. It now converts a line only when the target itself proves the instant. A line it cannot prove is skipped and counted in foreign_zone_lines_skipped. + +- **A Darling docs page lists every MCP tool and the store tables it reads** ([#6853]) - The page docs/darling/mcp-tool-tables.md lists 273 tools in three groups: tools that read collected data, tools about Darling itself, and tools that change something. A view or continuous aggregate is shown with its base table. Use it to find which tables hold the data for a tool. + +- **Darling can front several stores with one web address and one MCP endpoint** ([#6840], [#6917]) - A store is a Darling service with its own monitoring database. Add a frontDoor block with enabled set to true and one entry per store to darling.json, then restart. Each MCP call and web page goes to the store that holds the server, and a fleet-wide read returns one answer per store. The web dashboard gets a store picker, and the Fleet page and sidebar show the picked store first, marked "current". See docs/darling/front-door.md. + +- **The Darling viewer's Collector Schedules window has a Find box and a Disabled only filter.** ([#6768]) - The window lists about 70 collectors. The Find box filters by collector name as you type. The Disabled only check box shows only collectors that are turned off. Both can be used together. When nothing matches, the window says so. + +- **`get_job_history` takes a `min_duration_seconds` filter, and I/O anomaly briefs name it.** ([#6614]) - The filter keeps only job runs that lasted at least that many seconds. It applies before the row limit. A negative value is refused. The web read route and Custom Views accept it too. + +- **A signed-in web dashboard admin can make Admin writes on the managed store, once `web.allowAdminWrites` is on** ([#6600], [#6745]) - On the managed store, the web dashboard signed in to the store with a read-only login, so the Admin pages could only list. Now it keeps a second small connection pool that signs in as the managed admin role. That pool is used only for Admin writes by a person signed in as an admin, with the shared token or through OIDC. Reads stay on the read-only login. The writes are arming server-action switches, changing notification routes and webhook URLs, changing threshold overrides and undoing agent changes. The `web.allowAdminWrites` key in darling.json is read when the service starts, and a missing key means false, so an upgrade from 3.11 keeps those writes refused, as they were. New installs from the MSI and the install scripts write `"allowAdminWrites": true`. To get the same on an upgraded install, set it to true in darling.json. A store that the operator brings is unchanged. + +- **Darling now collects Query Store hints, lists them with `get_query_store_hints`, and Change Watch sees one set or cleared.** ([#6581]) - A Query Store hint changes plans like a forced plan, but nothing showed one being set or cleared. A new Darling-only collector reads the hints every 5 minutes and keeps them for 30 days (store migration V217). The new MCP read `get_query_store_hints` lists them. A new Change Watch kind, `query_store_hint`, reports a hint that was set or cleared. + +- **Agents can recompile a module and create or drop a plan guide through Level 3 server actions, with Undo.** ([#6569]) - Before, an agent that found a stale plan on a procedure, function or trigger had to run `sp_recompile` outside Darling, and nothing was journaled. The new `recompile_module` action does it with a journal row. The plan guide tools create and drop a guide, and Undo re-creates a dropped guide from the journaled definition. Each action needs its own per-server switch and defaults to a dry run. + +- **A request's brief names the earlier report with the same root cause** ([#6565]) - One root cause on one server could open a new request for each analysis story, and the agent had to find the earlier report by hand. Now the brief puts up to 3 reports from the last 24 hours with the same root fact first in earlier_reports, even when 10 newer reports exist. A request still opens as before. + +- **Client Timeouts alerts name the client host and carry a client_timeouts evidence section** ([#6553]) - Before, the alert detail named the client application and database but not the client host, and the investigation brief had no timeouts evidence. Now the alert card has a Top client hosts block, get_client_timeouts answers a top_hosts list, and a Client Timeouts request gets a client_timeouts evidence section. This applies to Lite and Darling. + +- **Darling MCP supports named tokens with roles, and an operator token can set a notification route's agent settings** ([#6542], [#6395]) - Before, Darling's MCP server took one bearer token and could not tell an operator from an investigation agent, so you had to serve write tools or investigation tools, never both. Now mcp.tokens takes a list of named tokens, each with the role operator or agent. Each caller sees only the tools of its token's role, and an agent's token name is its identity: a different agent_id on a claim, a Level 2 action or a plan action (force, unforce, evict, kill) is refused as agent_id_not_token. The server instructions are written for each role. --validate-config prints the named token findings and warns when no agent token is set while an enabled route has an agent level. An operator token can also set a route's agent fields: create_notification_route and update_notification_route take agent_level (0 to 3), agent_max_per_hour, agent_max_per_day, agent_lease_minutes and agent_expiry_minutes, and no other token can use them. The change is validated like a change in the viewer and it writes a route_agent_changed journal row. update_notification_route also takes clear_agent_level, which puts the level back to Inherit, and the undo call of a route write puts the agent fields back too. Before, these fields could be set only in the viewer or on the web dashboard. + +- **The Darling install scripts work with the MSI package and refuse a machine that the MSI owns** ([#6480]) - The install script takes -MsiPhase PreStart or PostStart so the MSI can run its non-service work, such as permissions, the operator group, the store folder and the firewall, without prompts. The uninstall script takes -MsiUninstall. The MSI records InstalledBy=msi in the registry. A plain install, upgrade or uninstall script run now refuses a machine that the MSI installed. + +- **The Darling installer offers to add you to the operator group** ([#6478]) - Before, you had to open Computer Management, add yourself to PerformanceMonitor Darling Operators, and sign out and in before the viewer or command line worked without elevation. Now the installer asks once at the end whether to add the signed-in person to that group. The answer defaults to No. The prompt appears only when the group exists. + +- **Darling prints the monitoring login and grant script, and the connection test names missing grants** ([#6472]) - The new --grant-script verb prints the login and the GRANT statements for a registered server or a host, with optional FinOps and Azure SQL Database sets. The Add/Edit Server dialog in the Darling viewer has a Copy grant script button and a FinOps checkbox. The connection test now checks the required grants and names each one that is missing. Before, you wrote about 15 GRANT statements by hand, and a missing grant only showed up later as a precondition status on a read. + +- **The Darling zip ships Install-Darling.cmd, and the installer offers to restart elevated** ([#6469]) - Before, install-darling.ps1 stopped with a message to use an elevated PowerShell, and on a default client Windows its execution policy blocked it. Now you can double-click Install-Darling.cmd. It asks Windows for administrator rights and runs the installer with the execution policy bypassed for that one process only. If you run install-darling.ps1 without elevation, it now offers to restart itself elevated. Arguments such as -Network pass through. + +- **A Darling page on how to back up, restore and move the store** ([#6411]) - There was no documented way to back up, restore or move the Darling store, and no disk-growth guidance. The new page, docs/darling-store-backup.md, has a pg_dump and pg_restore recipe tested against a compressed hypertable and a continuous aggregate, a move to a new host, the files outside the database (darling.json, keys and certificates), the managed, bring-your-own and Linux compose cases, and a section on how much disk the store uses, with size queries and the retention table. + +- **Darling MCP write tools return the previous value and an undo call** ([#6403]) - The mute rule tools, the notification route tools and the server admin tools (add_servers, edit_server and remove_server) now answer with the previous value and an undo call. The undo call is the exact tool call that puts the state back. Where no single call can restore the state, undo is null and an undo note says why. The edit_server undo carries the expected modified time, so a change made after the edit gives a conflict instead of an overwrite. Stored passwords are never put in the previous value or the undo call. + +- **Darling MCP get_server_settings reads what edit_server changes** ([#6402]) - The new get_server_settings tool returns a server's display name, engine, host, port, database, authentication, encryption settings, Query Store replica, monthly cost and modified_at. No password is returned. The monthly cost also shows in list_servers and get_collection_state as monthly_cost_usd. + +- **Darling MCP can switch agent actions off and undo a non-plan agent change.** ([#6401]) - Before, only the viewer and the web dashboard could turn the service-wide agent actions switch off. Only they could undo a mute rule, custom alert rule, threshold override or deadlock signature merge. The new MCP tools `set_agent_actions_enabled` and `undo_agent_change` do the same. Turning the switch on is refused over MCP because that is a person's decision. Both tools need MCP writes on and a token. + +- **Darling MCP can write, approve and reject agent notes, close an investigation request, and handle practice requests and report feedback.** ([#6400]) - Before, only the web dashboard and the viewer could do these. The new MCP tools include `write_investigation_note`, `approve_investigation_note`, `reject_investigation_note`, `close_investigation_request`, `start_practice_request`, `save_environment_profile` and `record_investigation_feedback`. They call the same store methods as the web routes, so the checks and journal rows are the same. They need MCP writes on and a token. + +- **Darling MCP has a purge_expired_mute_rules write tool** ([#6399]) - Before, only the viewer's Mute Rules window could purge expired mute rules. The new tool takes no arguments and deletes every expired rule. It lists the deleted rules in its reply. It is served only when mcp.allowWrites is on, and it is never offered to an investigation agent. + +- **Darling MCP can add, edit and delete known patterns.** ([#6398]) - Before, MCP could read known patterns but only the web editor and the viewer could change them. The new tools `create_known_pattern`, `update_known_pattern` and `delete_known_pattern` use the same store functions as the web routes. Each answer includes the before and after values and the call that undoes it. An update replaces the whole entry, as the web editor does. + +- **Darling MCP can read and set database state expectations** ([#6397]) - Before, only the viewer's database state window could set the state the Database State alert expects. The new get_database_state_expectations read lists each database with its current and expected state, whether the expectation is yours, and its status. The new set_database_state_expected write tool sets a state, sets IGNORE, or CLEAR to delete the row. It answers set, cleared or unchanged and gives the previous value and an undo call. The write tool needs mcp.allowWrites. + +- **Darling MCP can set a collector's database scope and reset a scope's schedules** ([#6396]) - The new set_collector_databases tool sets or clears the database scope that the schedule editor shows in its Databases column. The new reset_collector_schedules tool does what Reset to Defaults does in the editor. Both tools need mcp.allowWrites with a token, and an investigation agent is never offered them. Before, MCP could set enabled, frequency, run time and retention, but not the database scope. + +- **Darling MCP can make and remove webhook signing keys, for the default webhook and for each route.** ([#6394]) - Before, only the viewer could do this, and `update_notification_route` pointed at a step that MCP could not take. The new tools `generate_webhook_signing_key` and `remove_webhook_signing_key` take an optional `route_id`. No `route_id` means the default destination. They need MCP writes on and a token. + +- **Darling MCP can set the service flags** ([#6393]) - The new update_service_flags tool sets plan capture, Query Store backfill, the Query Store text budget in MB, the number of concurrent sweeps and the Query Store fetch top N. It needs mcp.allowWrites with a token. An investigation agent is never offered it. The range checks are shared with the viewer Settings window. Before, you had to use the viewer for these five. + +- **Darling MCP can set the default notification channels** ([#6392]) - The new update_notification_channels tool sets the channels that every route falls back to. These are the same settings as Settings, Notifications in the viewer. It covers SMTP, Teams, Slack, a generic webhook and PagerDuty. Only the arguments you give change, and a dash clears a text field. Before, MCP could change only the email cooldown and the send-resolution flags. + +- **The Darling viewer shows Fleet Sweeps, alert rules and Custom Views** ([#6390]) - The viewer has a Fleet Sweeps tab. It has an Alert Rules window with an editor and a Custom Views manager, and it runs Custom Views as dashboards and notebooks. The alert Triage link opens the server tab of the alert metric at the alert time. Pages that only the web dashboard has are listed in docs/tabs.md with the reason. Before, these existed only on the web dashboard. + +- **The web dashboard Recommendations tab has Generate now and Ask AI** ([#6389]) - The Recommendations tab on the web dashboard now has a Generate now button and a per-card Ask AI button, like the Darling viewer. Before, only the viewer had them, and analyze_now was reachable over MCP only. Generate now needs edit rights. + +- **The Darling viewer shows Resource Semaphore, Plan Cache by Type, Sessions by Application and more panels that the web dashboard already had** ([#6388]) - The viewer now has the Resource Semaphore Pressure, Resource Semaphore, Plan Cache by Type and Sessions by Application panels. It also shows table and index sizes under FinOps, Database Sizes. The PostgreSQL Overview tab shows the Extension Install Census under the Extensions grid. Before, these panels existed only on the web dashboard. + +- **The Darling viewer shows PostgreSQL configuration changes, the logging audit and deadlock graphs** ([#6387]) - The PostgreSQL server tab now shows a Configuration Changes grid with the old and new value, the scope and the kind of change. It shows the Logging Settings Audit, with a verdict for each logging setting and the recommended value. It also shows PostgreSQL deadlock graphs. Before, only the web dashboard and MCP had these. + +- **The web dashboard Active Queries panel can read the running requests live** ([#6386]) - A person signed in with edit rights can now ask the service to read the running requests from the monitored server right now, the same way the Darling viewer does. Before, the panel showed only stored snapshots. + +- **The Darling viewer charts the four PostgreSQL trends** ([#6385]) - Before, the viewer's PostgreSQL tabs held grids only, while the web dashboard had four trend panels. The viewer now charts the database trend, the query duration trend, the wait trend and the I/O trend. The database and query duration charts are in a new Trends sub-tab on Activity. The charts read through the same code as the MCP tools and the web dashboard. + +- **The Darling viewer shows Sweep Pressure and Heaviest Collectors panels** ([#6384]) - The web dashboard's Collection Health tab had these two panels and the viewer did not. The viewer's Collection Health tab for SQL Server now has a Sweep Pressure sub-tab. It shows the sweep verdict, busy percent, peak cycle and peak risk, and the three heaviest collectors. Both panels cover the last 7 days whatever the toolbar window is. +### Changed + +- **Recommendations say "times its usual variation" instead of "robust σ"** ([#6925]) - The anomaly advice now says "at least 25 times its usual variation above its normal level" where it said "at least 25 robust σ above its baseline median". It is text only. No number or threshold changed. This applies to Lite and Darling. + +- **Updated to .NET SDK 10.0.403, DuckDB.NET 1.5.6.1 and newer AWSSDK and ProtectedData packages** ([#6915]) - The self-contained Lite and viewer builds now carry .NET runtime 10.0.14 instead of 10.0.13. + +- **Client Timeouts leaves out the VS Code mssql extension's metadata cancels** ([#6856], [#6858]) - The alert counted the extension cancelling its own metadata queries, as it did for SSMS IntelliSense before. It now leaves out five known vscode-mssql connection names, matched exactly and ignoring case. Any other name stays counted. The alert summary and get_client_timeouts name the tools whose samples were left out. This applies to Lite and Darling. + +- **get_forced_plans and get_query_store_hints read each first-seen time in one pass** ([#6833], [#6876]) - Each call found first seen with one scan per output row. With 500 forced plans, 4.6 of 5.3 seconds went to that scan, and 345 hints took about 2 seconds. Both are now one grouped read with the same values. This applies to Darling MCP and the web dashboard. + +- **The 31-day daily summary keeps closed days until the next UTC day plus 2 hours** ([#6809]) - The web Overview, the web calendar and the Darling viewer calendar used to reread about 30 closed days from cold. This happened at the first load after every hour. That read took about 8 seconds on a store with 42 servers. Closed days now stay cached and today stays live. Days before the retention horizon are reread once an hour so a purge still shows. + +- **get_query_store_clutter and the Darling viewer's Query Store clutter view are faster on large servers** ([#6808]) - The plan churn read no longer sorts every raw row twice. Over 7 days on a server with about 2.4 million rows, warm time fell from about 7 seconds to about 1.3 seconds with identical results. + +- **Darling viewer Top Queries by Duration looks up modules only for the ranked statements.** ([#6804]) - The module lookup ranked every retained `procedure_stats` row of the server. On a store with 42 servers that was 10 to 12 seconds of a 13.4 second first call. It now keeps only the ranked handles, as Lite already did. + +- **FinOps High Impact and Optimization are faster, with no temp spill.** ([#6803]) - High Impact ran four lookups for every query hash, about 330 on a busy server, and kept only a few dozen. It now ranks first and looks up only the kept hashes. Optimization grouped the whole window's text and plans, which wrote about 345 MB of temp data per call. It now groups on narrow keys and looks up the text per group. The web dashboard, MCP and the viewer all get the change. + +- **The Darling fleet `get_resource_use_by_tag` read is much faster: it reads narrow hourly and daily tables and is served from the read cache** ([#6800], [#6794], [#6865], [#6945]) - With no server named, the read used the raw tier for plan cache and procedures, about 10 to 13 GB per statement on a store with 42 servers, and its Query Store part read the whole window from the wide interval table. A cold visit took 61 to 118 seconds. Plan cache and procedures now use the hourly rollup when it covers at least 75 percent of the window, Query Store is read in one statement and not one per server, and a window of 24 hours or more is cached for 5 minutes. Store migration V221 adds narrow hourly and daily Query Store tables for the roll-up. After the upgrade the service builds up to 30 backlog hours per collection tick instead of about 3. A fleet read answers from the newest span that needs no backlog and says how many hours it left out and why. The MCP and viewer roles cannot see another role's transaction start time, and a read by those roles no longer falls back to the slow wide table because of that. + +- **Darling's Job History page reads its per-job statistics from a new index** ([#6798]) - The average run time and last success for each job now come from a partial index of successful job runs (store migration V220). The page reads that index one job at a time. Before, a cold page read about 3,700 scattered history rows per server and threw most of them away. A cold call took 8.6 seconds on a store with 42 servers. + +- **`--backfill-rollups` and `--recompress` can take the store's free space, and the data volume is measured on Linux.** ([#6791]) - When the store is on another host or a managed service, the verbs could not check free space from the machine that runs them. The new `--free-space ` option takes the number you checked on the store host and runs the same room check on it. A login without superuser rights still gets a refusal that says which grant is needed. + +- **Query Store regressions list a query for cost only when it added at least 1 second of CPU** ([#6781]) - Before, a query was listed when its CPU per run rose more than 25 percent, even for a few runs of a cheap query. On one store with 42 servers, 80 to 96 percent of the cost rows added under 1 second of CPU over the whole window. A query now needs the 25 percent rise and at least 1 second of added CPU over the recent window, in Lite and Darling. A daily job that got much slower is still listed. + +- **A re-fire of an alert now joins a request that is already reported, so it opens no new request.** ([#6778]) - One High CPU episode that re-fired about every 5 minutes for two hours made 22 requests, and all 22 counted against the route's limits. A reported request now takes the re-fire when three things hold. The server, family and metric match, the severity is not above the request's maximum, and the request is not resolved. The grouping window and 4 hour cap still apply. This applies to Darling and Lite. + +- **The Darling viewer and Lite Running Jobs tabs now show a short note when the collector has not run.** ([#6764]) - Before, they showed the full 1200 character answer written for MCP clients, ending in "runtime PRECONDITION". The web dashboard, the viewer and Lite now use the same words. + +- **Four MCP empty answers now say what kind of nothing they are.** ([#6757]) - `get_database_state_expectations` told a PostgreSQL target, an Azure SQL Database and a SQL Server target before its first run the same thing. It now separates them. `get_query_heatmap` on Lite answered `unavailable` on an idle server whose collector ran clean. It now answers `empty`, as Darling does. `get_database_config` filtered to an unknown name now says master, model and msdb are never collected and a newer database is absent. The `get_wait_stats` and `get_wait_trend` descriptions now say a wait is counted only when it ends. + +- **Web server add and edit now refuse Windows sign-in over an unverified certificate unless the operator allows it, as MCP does.** ([#6752]) - Before, `POST /api/servers` and `PATCH /api/servers/{id}` ran no such check. A web add or edit could save a Windows authentication server with `trust_server_certificate` true or `encrypt_mode` Optional. The new setting `web.allowWindowsAuthOverUnverifiedTls` defaults to false. + +- **`analyze_server` now ranks a long blocking chain by how long it waited and says when it is still open.** ([#6746]) - Before, an idle session held locks in an open transaction for 13 minutes. The finding had low severity and confidence 0.2, below old plan regressions in other databases. The advice also said the chain had cleared long ago. `BLOCKING_CHAIN` severity now also counts the longest wait (concerning at 30 seconds, critical at 300 seconds). The fact describes the worst chain, not the largest one. It says whether the chain was still open at the end of the window. + +- **Self-managed store upgrades now say to re-run provision-roles.sql, the two CLI verbs accept the same `--auth` words, and a per-server collector retention is refused.** ([#6743]) - Self-managed store: after an upgrade from 3.11, the MCP route, signing key and default channel tools failed with a generic PostgreSQL error. They now answer with one sentence that says to re-run `Darling/tools/provision-roles.sql`. CLI: `--add-server` refused `integrated` and `--grant-script` refused `windows`. Both verbs now take either word. Retention: `set_collector_retention` with a `server_name` stored a value that the purge never read. It is now refused with a reason. + +- **`submit_investigation_report` now tells an agent that `family_of` needs the full request id.** ([#6729]) - Before, the 8 digit short form gave only "family_of: not a request id." Now the refusal asks for the full request_id, a UUID. It names the short form as the mistake. Darling and Lite share the same text. + +- **The Darling upgrade script now prints a post-upgrade checklist that an operator can work.** ([#6724]) - The old checklist was five SQL lines with terms like "rung" and collector counts. The new one lists checks you can do on screen about 10 to 15 minutes after the start. Every monitored server shows Online, each server card shows Collectors OK and Failing 0, and the service log has a "Postgres store ready" line for this start. The Darling README has the same checks. + +- **Five MCP tool descriptions are fixed where agents guessed wrong** ([#6713]) - A replay of six past investigations found five description problems that each cost a wasted call. For example, get_top_queries_by_cpu takes top, not limit, and its description now says so. The text is fixed in Darling and Lite where the tool exists in both. Behavior is the same, except one message in the get_tool_guide answer that takes no arguments. + +- **The Darling viewer and Lite match the web dashboard on dropped databases, labels, job history, wording and strip gaps** ([#6651]) - Top Procedures by Duration now leaves out dropped databases, so they no longer use up the row limit. The Job History Last Success column is gone. FinOps Utilization labels say SQL Server CPU. The Memory tab says Plan cache (all cache stores). The Settings text no longer names MCP tool fields. The time range strip on Top Queries and Top Procedures breaks at gaps in the data. Lite got the same changes where it had the same behavior. + +- **The health parser says how many events were read when it finds none that qualify** ([#6650]) - Before, the truncation message always began with No events were found, even when the read had counted hundreds of events and its filter left none. Now it says how many events were read and why none qualified. It still says that this is not an all-clear. This applies to Darling and Lite. + +- **The hourly Darling aggregate compression check reads sizes only for aggregates that have no policy** ([#6648]) - Every hour the check read the hypertable size and two chunk counts for all 29 continuous aggregates. That cost grows with the chunk count. Only the first-run staging for an aggregate without a compression policy uses those numbers. Now the check reads them only for those aggregates. + +- **get_store_log gives the TimescaleDB poor compression ratio warning its own class** ([#6647]) - The warning that a chunk had a poor compression ratio used to show as unclassified, so it looked like an unexpected warning. It is harmless. A tiny chunk compresses to a larger size because the compressed format has a fixed overhead. It now has its own class, compression_ratio_warning. + +- **The PARAMETER_SENSITIVITY and QUERY_SPILLS findings now name the queries behind them.** ([#6640]) - Before, an agent read the finding but could not tell which queries caused it. PARAMETER_SENSITIVITY now names the database, query hash and plan hash with the worker ratio. QUERY_SPILLS names the top three queries by spilled pages. The finding text and `get_analysis_facts` show these names. + +- **Store migration V215 adds six indexes on the Darling investigation tables** ([#6637]) - A copy of a store with one year of synthetic investigation requests showed reads that were slow at that size. With the indexes, the follow-up module read fell from 127 ms to 5.5 ms. The due follow-ups read fell from 35 ms to 0.7 ms. The list_investigation_requests tool and the 30 day reports read fell from 25 to 53 ms to under 1 ms. The retention delete of requests fell from 310 ms for 8 rows to 0.5 ms. + +- **The investigation resolve check is about 5 times faster in Darling and Lite.** ([#6633]) - The check runs once a minute. It now tests only alert log rows newer than the oldest last alert among the live candidates, so older rows skip the per-row text test. No candidate is dropped. + +- **The Blocking Incidents chart says why it is empty when lock waits exist** ([#6622]) - Before, the chart said there was no blocking in the time window even when the lock wait chart showed many LCK_M_X waits. The two charts count different things. An incident needs a blocked process report or a wait of 2 seconds or more. Now the empty chart in Lite and in the Darling viewer says that no lock wait lasted long enough to count as an incident. It adds that shorter lock waits show only in the lock wait chart. + +- **Darling opens no investigation request for a story that recurs at this hour** ([#6596]) - A weekly index and statistics job can push data file latency far over the baseline in the same hour every week. Before, each such alert on an agent route opened an investigation request. An agent then spent a claim and about ten tool calls to report maintenance with no action. Now, when every story behind the alert carries the recurring at this hour label, no request is opened or joined. The skip is logged and journaled. The alert, its severity and its delivery do not change. + +- **Darling and Lite MCP tool descriptions are reworded where investigation agents went wrong** ([#6589]) - Six test agents replayed real investigations, and 11 of 44 calls were wasted on wrong arguments or the wrong tool. The descriptions are now clearer at those places. For example, the family argument of get_alert_history says it is not an investigation family such as blocking, and that you filter those with metric_name. + +- **A SQL Server port is refused on new entries and warned about on existing ones** ([#6583]) - A SQL Server entry's port field was stored but never used for the connection. Now add_servers, the web add route and --add-server refuse a non-zero port on a SQL Server target and say to write it in host as host,port. edit_server accepts port 0 so you can clear an old one. --validate-config warns about each existing SQL Server entry that has a port. A failed connect no longer names that port. + +- **get_forced_plans pages its list and filters by query_id and plan_id** ([#6560]) - Before, the tool listed at most 200 forced plans with no paging and no filter, so on a server with 349 forces you could not read the rest. It now takes query_id, plan_id, limit and offset. The default page is still 200. The reply adds matched_forces, has_more, next_offset and a page_note. + +- **The Darling web dashboard and MCP server, and Lite's MCP server, need a token once turned on** ([#6507], [#6557]) - Before, a loopback-only start with no token served every request with no credential. Now Darling's web dashboard and MCP server do not start without a token and log one Critical line that names the settings to add. The settings web.allowTokenlessLoopback and mcp.allowTokenlessLoopback opt out and serve reads only. Lite's MCP server now answers 401 to any request without a valid bearer token. Lite makes its own token the first time the server starts, and the Settings tab has a Copy MCP config button. + +- **The Darling command line tests Windows authentication servers as the service** ([#6476]) - Before, --test-connection and --add-server tested a server as the person at the console. For a Windows authentication server that is the wrong account, so a pass could be followed by a login error in the service. Now the command line asks the running service to run the test, as the viewer does, and says "Tested by the running service, as the account it runs under". If the service cannot be asked, the command line tests the server itself. --add-server also takes flags for one server and prompts for the password with hidden input. + +- **--enable-web and --enable-mcp print the address and the next step** ([#6474]) - Before, these two verbs said the endpoint was on and stopped. Now --enable-web prints the dashboard address and the --print-web-token verb that shows the token. --enable-mcp prints the address, the claude mcp add command for Claude Code and the --print-mcp-token verb. The address uses the port the service binds. + +- **The Darling viewer finds darling.json through the installed service** ([#6473]) - Before, the viewer looked for darling.json only at an explicit path, in DARLING_CONFIG, beside the viewer and one folder up. Now, when all of those miss, it reads the path the Windows service is registered with and uses the darling.json in that folder. It needs no elevation to do this. The startup diagnostics name this source and the full path. + +- **The Darling Windows zip no longer needs a separate .NET runtime** ([#6471]) - Before, install-darling.ps1 stopped when the .NET 10 Runtime or the ASP.NET Core Runtime was missing, and you had to install both and run the installer again. The service and the viewer in the Windows zip now carry their own runtime, as Lite already did, and the installer no longer checks for one. + +- **The Darling installer waits until the service is ready and then prints the next steps** ([#6470]) - Before, the installer waited up to 60 seconds for the service to be running, said to give it about two minutes and printed Done. Running only means the process is up. The first start still unpacks the bundled PostgreSQL, creates the store, migrates it and sets up roles. Now the installer waits up to 420 seconds for the service to be ready. It shows progress from the service log and prints what to do next. + +- **Darling starts with no monitored servers, and a first install needs no hand-edited darling.json** ([#6468]) - Before, the service refused an empty servers list, and the installer copied the sample darling.json and exited with code 2 until you edited it. Now an empty or missing servers list is valid. The service creates its store and logs one Information line that says to add a server in the viewer or with --add-server. It starts collecting from a new server without a restart. With no servers, --validate-config and --test-connection exit 0 and say there is nothing to test. + +- **Darling says a Query Store replica has no effect on Azure SQL Database** ([#6459]) - Before, edit_server, add_servers and the connection tests accepted a Query Store replica for an Azure SQL Database and said nothing, although Darling never reads a replica there. Now the reply says the setting is not used and has no effect, both when you save and when you test. The save still goes through. + +- **The troubleshooting page is a symptom table for Lite and Darling** ([#6422]) - The page has two halves, one for Lite and one for Darling. Each half is a table of symptoms with the cause and the fix. The Darling half now covers first-run failures that other files used to describe. These are the CET start failure, a blocked port, an Entra sign-in problem, a service account that cannot read the install folder and initdb failures. + +- **The Lite README is a short front door, and the Lite guide puts install and configuration first** ([#6419]) - The Lite README now says what Lite is, gives a three-step install and links to the guide. The ZIP size history is gone from the README and the guide. The CET start failure moved to the troubleshooting page. The Lite guide now puts install and configuration first, and the long Extended Events section comes after upgrade, storage and configuration. + +- **The Darling install docs now tell one story** ([#6417], [#6418], [#6409], [#6410], [#6429], [#6430]) - The long onboarding guide is split into short Darling pages for install, the viewer, the web dashboard and MCP. The root README names the install script, the folder and the rule that darling.json is only a seed. The Darling README no longer says that Darling needs PostgreSQL that you set up yourself. It no longer says that Darling runs only as a Windows service or has no UI. Its upgrade examples are no longer pinned to an old version. The MCP setup page now has Darling steps next to the Lite steps, including the port, the token and the switches. The Configuration Reference says which darling.json keys are first-run seeds and which are file-only. + +- **The Darling documentation is reorganized into task pages with an index** ([#6416], [#6420]) - The Darling README had grown into one long page. Its sections moved to task pages under docs/darling/, the pages that repeated each other were merged (the two MCP pages and the viewer tab tables), and the history notes moved out of the task pages. docs/README.md is now an index, and every page carries an Audience line. The two PostgreSQL design notes moved to docs/design/, and the old paths hold a one-line stub that links to the new file. + +- **New Darling pages for day-to-day admin tasks and for every service command line verb** ([#6412], [#6413]) - The admin page covers adding and removing a server, changing a monitoring password, rotating the web or MCP token, pausing and resuming collection, upgrading and uninstalling. The command line page has one row for each verb of the service exe. Each row says what the verb does, whether it needs elevation, whether the service must be running and which exit codes it returns. + +- **The Client Timeouts alert is on by default in Darling and Lite** ([#5736]) - A 7 day replay on a store with 42 servers paged twice, both times as Warning. Store migration V216 sets the Darling default to on. It also moves a stored off value to on, because that stored off was the old default and not a choice. If you really had it off, switch it off once more after the upgrade. Lite does the same once, with a marker in settings.json. + +- **The Query Store regressions read and `get_collection_health` are much faster on large Darling stores, and the regressions read no longer misses cost regressions on long windows** ([#5506], [#6750]) - On a store with 42 servers, a cold 24 hour `get_query_store_regressions` call took 18 to 22 seconds. The read now runs the monitor's own statement test only on flagged rows, takes its Regular rows from `query_store_interval_latest`, reads whole built days from the daily totals, finds the monitor's own statements through a key table (store migration V219) and uses a shorter, measured purge edge margin. The viewer's Regressions grid gets the same change. A cold 24 hour call now takes about 3 seconds, and a cold 168 hour `get_collection_health` call fell from 10.5 to 0.7 seconds. The read also had a baseline problem. With a 168 hour window on a store that keeps about 4 days of raw data, the cost baseline was empty, so cost could never flag, and the note said the baseline held "only the part from effective_start to baseline_end". Each arm of the read now starts from the earliest data it can actually use, the note says plainly when the baseline is empty, and per-hour rates divide by the hours of data that exist, so a failure rate that had not changed is no longer flagged as a rise. The key backfill after the V219 upgrade runs faster on large stores too. On a copy of a large store the cold run fell from 452.9 seconds to 157.8 seconds with the same 156,086 keys. +### Fixed + +- **The Darling web dashboard keeps the page on screen while it auto-refreshes** ([#6933]) - Each refresh cleared the page and drew it again. Fleet and Availability Groups blinked "Loading...", server pages refilled each panel one by one, and the scroll position jumped. A refresh now keeps what is on screen and swaps only the data. Going to another page, server, tab or range still renders fresh. + +- **Blocking chains in analysis no longer link unrelated sessions that reused a session number** ([#6931]) - The BLOCKING_CHAIN fact and its drill-down, in Lite and Darling, rebuilt chains over the whole window keyed on spid and ecid. SQL Server reuses spid numbers over hours. Edges from different minutes then formed chains and cycles that never existed, and later chains reported 0 victims and 0 ms. They are now scoped by scan, as the viewer and the web page already were. + +- **The Darling web Overview strips draw at full size, and the Daily Health Calendar fills its card** ([#6929]) - On a wide Overview tab the strips were scaled to about 62 percent, so the crosshair, readouts and drag-to-zoom brush sat away from the pointer. The calendar used only half to two thirds of a wide card because of a width cap. Both are fixed. + +- **Saving an edit to an existing notification route from the Darling web page works again** ([#6928]) - Saving an edit to an existing route from the web page always failed with HTTP 400 "expected_modified_at is required", since 3.11.0. The edit form dropped the route's last-saved time when it read its fields back. The form now sends it. + +- **The Darling upgrade script runs under PowerShell 7** ([#6920]) - The step that restricts the rollback backup folder read its permissions with GetAccessControl methods that exist only in Windows PowerShell 5.1. Under PowerShell 7 it failed with "Method invocation failed" and the upgrade stopped. The script now uses the DirectorySecurity and FileSecurity constructors, which work in both. + +- **Unregistered external alerts from different sources or labels stay in separate investigation requests** ([#6919]) - Such alerts arrive with server id 0, and they used to join one request inside the 30 minute window. A runner then sent one source's alert to an agent that handles another. Alerts for registered servers group as before. + +- **Idle servers answer empty, not unavailable, for query_stats and procedure_stats reads** ([#6903]) - get_query_heatmap, get_query_duration_trend and get_procedure_duration_trend answered unavailable on an idle SQL Server. Every query_stats run writes a measurement note, and the check for a clean run needed a blank note. A note that holds only measurement counts now counts as clean. This applies to Darling MCP. + +- **The new Agent Alerts, Database Protection and Identity Capacity views read cleanly** ([#6901], [#6906], [#6907]) - In the Darling viewer the empty-grid note was drawn over the column headers, and the status sentence was repeated. The note now sits below the headers. The server pickers on these tabs listed every server ever registered, so a removed and re-added server appeared twice. They now list the managed servers. On the web dashboard a long detail sentence stretched a three-column metric tile past its card. The tile now stays inside the card, and the full sentence is in a tooltip. + +- **Azure SQL Managed Instance system_health events are collected again** ([#6897]) - Managed Instance refuses both a directory path and the system_health_0_*.xel pattern with error 40538. Each run fell back to the ring buffer. That buffer is cut at about 4 MB and keeps the oldest events. Nothing new was stored, and the health-parser reads answered unavailable. The collector now reads the bare system_health*.xel pattern there, in Lite and Darling. + +- **The blocking snapshot no longer names its own session as the blocker** ([#6896]) - Memory-grant waits (RESOURCE_SEMAPHORE) listed the snapshot's own session as the blocker, with the snapshot query as the text. get_blocking and the Blocking Detected alert then blamed the monitor. Those rows are now left out of the snapshot, and the waiting tasks table stores a NULL blocker for them. + +- **Extended Events captures that cannot run are no longer counted as healthy or as down** ([#6893], [#6912]) - In Lite and Darling, a failed create of a deadlock or blocked-process session was logged and forgotten, so collection health read HEALTHY. A refused create now records a permissions problem or a missing session, so collection health and the Capture Down alert show it. Amazon RDS Web and Express refuse every Extended Events session. On those editions the four captures answer as not collected with the edition limit stated, and no create is attempted (store migration V226). Capture Down and collection health no longer count captures the engine does not run. The alert resolves as "Capture Cleared". + +- **Darling no longer writes its own ERROR lines into a monitored PostgreSQL server's log** ([#6888]) - Four checks relied on the target raising an error: the extension query, the Aurora check, the identity check and the store's install-ID check. The identity check wrote "permission denied for function pg_control_system" on every non-Aurora connect. A DBA saw errors from the monitor, and the error family in get_pg_log_events filled with them. Darling now asks first and sends the call only when it is allowed. A collector whose extension is missing is recorded as extension missing, with the same message. + +- **Azure SQL Managed Instance now reads SQL Agent as running** ([#6886]) - The collector read the Agent from sys.dm_server_services, which returns no rows on Managed Instance. The Agent showed as "no SQL Agent service found" in get_job_history and the instance was listed under agents_not_running. The collector now reports Managed Instance as running with "Running (managed by Azure SQL Managed Instance)". Other engines are unchanged. + +- **The Darling viewer fleet card shows the whole Collectors line, and query tag text uses words** ([#6878]) - At 1366x768 the card's Collectors line was cut before the "Not collected" count, so it now wraps. The Blocking Trends chart's axis title is "Blocking events", and the collector that answered is named in the legend. The Resource use by query tag dialog in Lite and the viewer shows "Plan cache" and "CPU (ms)" like the web page. The FinOps OVER_PROVISIONED sentence states the buffer pool share without calling it "only". + +- **Deadlocks and blocked process reports are collected again on Azure SQL Managed Instance** ([#6868]) - Managed Instance reports execution_count as 0 on every Extended Events target. The collector skips a target when the count has not changed. After the first run it saw 0 equal to 0 and never read the ring buffer again. A count of 0 now reads the target on every run. This applies to Lite and Darling. + +- **The tempdb tab explains why it is empty in Lite and the Darling viewer** ([#6861], [#6869]) - On an Azure SQL Database with a contained login, tempdb_stats is refused with error 262 and the tab showed three empty charts and no text. The tab now shows the reason in a note on its own panel, so the chart axes no longer draw through the text. The note no longer carries a sentence written for MCP clients. + +- **get_job_history and get_resource_use_by_tag answer with the display name, not the connection key** ([#6860]) - The answer's server field and the not-collected sentence used the registry connection key. Darling's get_active_queries in its snapshots_only form and Lite's get_resource_use_by_tag did the same. All of them now use the display name. The web route for get_job_history is fixed too. + +- **Lite logs a permission-denied collector run as one Warning** ([#6859]) - Lite wrote an Error line and then a Warning for each run of a refused collector. One example is a contained login on Azure SQL Database that cannot read the tempdb view (error 262). With the back-off that was about 24 pairs a day for each collector. It now writes only the Warning, as Darling does. + +- **A missing Resource Use By Tag source is named in the same words in Lite, the Darling viewer and the MCP tool** ([#6850]) - The viewer said "no dmv blocking snapshots data yet", and get_resource_use_by_tag said "collect.deadlocks does not exist in this store yet." All three now build one sentence from one table of source names, such as "blocked process report". + +- **PostgreSQL 10 to 13 targets store statement stats and wait samples correctly** ([#6836], [#6849]) - Since 3.11, pg_statement_stats threw "Column 'wal_records' is null" on every PostgreSQL 10 and 12 target and stored nothing. The WAL counters now stay NULL where the extension has none, so get_pg_top_queries shows wal_bytes as null instead of 0. A wait sampling target upgraded from 13 to 14 now moves its NULL query id series to 0 and does not repeat them every cycle. The get_pg_wait_sampling tool explains a null queryid. The docs name the support tiers: 14 to 18 supported, 10 to 13 best effort. + +- **The slow-read log records the server when the server id is negative** ([#6834]) - A server id is a hash of the server name, so about half of all servers have a negative id. For those servers every server-scoped tool's slow-read row stored a null server and no server_id argument. The row now records the server. This applies to Darling. + +- **Charts keep a plot at least 100 pixels tall at 1366x768, and axis titles stay clear of tick labels** ([#6832]) - Three chart tabs with a large legend left a plot about 30 to 45 pixels tall, and the rotated y title was cut to "Read Latency (m". The chart layout now raises the row minimum by the space the legend and ticks use. This applies to Lite and the Darling viewer. + +- **Four Darling web pages use the page's own words instead of MCP text** ([#6831]) - Query Tag Usage showed raw ISO stamps and collect. relation names. The empty Query Store regressions panel said "effective_start (see hints)". System Events showed a long internal event name, and FinOps Recommendations said "database(s)" with a dash. Each page now uses plain words. + +- **get_finops refuses an unsupported hours_back for the utilization and index_analysis views in the view's own words** ([#6830]) - The shared range check ran first. A value of 336 got "exceeds maximum of 168 hours" and 0 got a range message, which suggested values the view then refused. Every value except 24 now reaches the view's own message. This applies to Darling MCP. + +- **get_query_store_regressions explains a baseline or replay window that is older than the kept data** ([#6829], [#6877]) - On a store that keeps about 4 days of raw data, a 168 hour read said it found no capture in the baseline window. An as_of replay older than the raw data said no sample was stored yet. The tool now says the window is older than the raw data and names where the data starts. It says retention may have removed the older data. It also carries effective_start and window_truncated. This applies to Darling MCP. + +- **Collector counts agree on every Darling surface, and a refused collector names the grant** ([#6828], [#6932]) - A quiet attention capture is no longer called a regression. The Darling viewer now applies the same produced-then-stopped rule as the MCP tools. Before, one server showed 39 healthy in get_collection_health, 44 in the viewer card and 41 in the web header. The five counts now always add up to the total, including a new no permission count. A refused agent_alerts collector says to grant SELECT on msdb.dbo.sysalerts and msdb.dbo.sysnotifications to the monitoring login. The other msdb collectors name their own grants. + +- **Health-parser reads check for a truncated ring buffer over their own window** ([#6827]) - Before, they asked only about the collector's newest run. A replay of a window whose runs were all truncated answered empty, and a clean past window answered unavailable when today's run was truncated. The check now reads every run inside the window plus the first run after it, in Lite and Darling. + +- **Save is visible in the Darling viewer's Add and Edit server dialog at its default width** ([#6823]) - The bottom row was wider than the 450 pixel window, so Save was pushed off the right edge until you widened the window by hand. Save and Cancel now sit on a row of their own below the other controls. + +- **The Darling upgrade script takes a new rollback backup when the last upgrade finished** ([#6821]) - Before, the script reused the newest backup whenever it was less than 60 minutes old. Two complete upgrades within one hour then shared the first backup. A revert then laid older root files over newer subfolders. The script now reuses a recent backup only when the upgrade that took it did not finish. + +- **Darling Query Store panels over a window older than 3 days are no longer refused by the row guard** ([#6807]) - Those panels read the hourly rollup, but the guard sized the wide interval table they never touch. A 7-day notebook over 42 servers was refused at about 53 million rows against a limit of 6.8 million. The eligibility check also reads each server's table floor in one statement instead of one per server. That saves about 0.75 seconds a panel on that store. + +- **The slow-read log now keeps a read's slowest statements, and records a web read that the browser cancelled.** ([#6795]) - Before, the log kept the first 50 statements of a read. One 140 second read was stored with probes of 5 to 126 ms, and its three big aggregations were missing. The log now keeps the 50 slowest statements. A cancelled web read now reaches the log. + +- **Darling web pages cancel their reads when you leave the page** ([#6793]) - Before, a slow read from the page you left kept running. It blocked the 60 second poll, the Refresh button and the tab-return refresh on the next page. The footer then showed "(slow page)" and the refresh backed off. Each page now counts and cancels its own reads. Query Tag Usage is no longer re-read by the 60 second poll. + +- **The Overview tooltip's baseline arrow now shows only for the first series of a chart row.** ([#6787]) - A chart row has one baseline, and it belongs to the first series. Before, the tooltip judged every series against it. Total CPU got a red triangle when it sat above SQL CPU's band, with no matching dot on the chart. This applies to Lite and the Darling viewer. + +- **The Wait Drill-Down banner is now readable on the Light and Cool Breeze themes.** ([#6773]) - The banner text was light blue or amber, picked for the Dark theme, and was pale on a pale page. It now uses theme brushes. This applies to Lite and the Darling viewer. + +- **A server's own Capture execution plans setting now takes effect.** ([#6771]) - Before, the per-server `capture_plans` value was stored but never read. The service-wide setting decided for every server, though the Settings text pointed at a per-server control. Now NULL follows the service setting. True keeps plan XML for that server even with the service setting off. False collects statistics without plan XML even with the service setting on. An edit takes effect on the next cycle with no restart. + +- **The Darling viewer logs a failed schedule read once, not once per waiting caller.** ([#6766]) - Before, one failed read logged up to four warnings, one for each caller that was waiting. It logged them again on every refresh while the store could not be read. + +- **Investigation blocking evidence no longer counts parallel self-waits, keeps the head blocker's facts, and honors the high-memory signal.** ([#6761]) - Before, a parallel query's self-wait used up the 500 row cap. It also made a blocked session its own head blocker, so `head_blocker` named the wrong session. Some head blocker facts were empty when a blocked-process report covered the same pair in the same minute. These were login time, last request end, open transaction count and log bytes. The memory flag also ignored the high-memory signal. Now it counts it. + +- **Darling web: an empty Add route or Write note says what is missing without a request, and Running Jobs and Recommendations text reads plainly.** ([#6760]) - The Admin page now checks the field first and shows the message without sending a request that returns a 400. The Running Jobs panel showed a 1222 character answer written for MCP clients. It now says which data is missing and keeps the causes the server names. A Recommendations card that read "HIGH 0.80 waits" now reads "HIGH (score 0.80) · waits". + +- **Four Darling web pages no longer say two things at once.** ([#6759]) - The Queries tab showed two near-duplicate banners. It now shows one. The Overview CPU tile said "CPU 20%" next to a header chip that says "Total CPU 25%", so the tile now says SQL CPU. Running Jobs called an empty list normal even when the server's collection was stale. It now says the data is stale. The sign-in page now says "SQL Server and PostgreSQL monitor". + +- **Darling viewer fixes to the grant script account, PostgreSQL notes and sidebar buttons.** ([#6758]) - The Copy grant script (Windows authentication) command named the wrong account. It now reads the service's real account, and says so when the service is not on this machine. The PostgreSQL Database Trend note no longer says "the biggest temp-file spiller" when nothing spilled. PostgreSQL notes show the real collection cadence, not a fixed one, so a schedule override is reflected. The sidebar buttons Open Plan Viewer, View Log, Open Log Folder and About, and two close buttons, now have accessible names. + +- **Three web layout fixes in the Darling dashboard.** ([#6756]) - The server tab strip now wraps, so the last tab is no longer cut off. Recommendations text keeps a readable minimum width on phones. The Overview Waits strip now starts at 0, so a small swing no longer looks like a spike. + +- **Lite keeps its first-run server step until the servers are bound to their settings.** ([#6755]) - On the first start of a 3.12 build over an existing 3.11 data folder, Lite wrote its "used before" marker before it bound servers. If the store failed to open or the window closed first, the next start skipped the step. Every server stayed unconfirmed, and SQL login servers needed their passwords typed again. The marker is now written after the binding. + +- **Query Store reads now give the right status word on a Secondary role, with Query Store off, and for an empty forced-plan window.** ([#6749]) - Four reads gave the wrong status word: `get_query_store_top`, `get_query_store_duration_trend`, `get_forced_plans` and `get_query_store_hints`. They answered `not_collected` on an instance whose role read Secondary. That instance can still host databases outside any availability group that the collectors read. They now check the health capture first. With Query Store OFF or in ERROR, `get_query_store_hints` answered `unavailable`. It now answers `precondition` with the statement to run. An empty forced-plan window now answers `empty`. This applies to Lite and Darling. + +- **Stopping the Darling service during a pass no longer logs a false alert-pass warning.** ([#6748]) - Before, a stop at the wrong moment could log "External alert pass failed" with a "disposed object" error. The collection loop now handles the stop and runs its normal shutdown. + +- **The viewer now shows fleet-wide times in a fleet-wide zone, and each server tab's times in that server's own zone.** ([#6747]) - Fleet Sweeps, its time picker and the Custom View run window chart used the clock of whichever server tab refreshed last, with no zone label. The Custom Views "Saved" column ignored the Server, Local and UTC mode. A server tab's "collected" time could show another server's offset. All of these now use the right zone and say which. Two quick selection changes in the Custom Views list no longer leave the grid and editor on different views. + +- **The generated grant script and the permissions doc now loop databases with a cursor, not `sp_MSforeachdb`.** ([#6741]) - `sp_MSforeachdb` is undocumented and can skip databases. It also replaced every `?` in the batch. A login name with `?` or a database name with unusual characters gave a wrong or failing grant. The FinOps part of `--grant-script --finops`, and the viewer's copy of it, now loops over writable user databases and quotes names safely. + +- **Journal rows for refused agent actions, plan undo and operator route changes now record the right caller.** ([#6740], [#6751]) - Before, a refused bad `agent_action` was journaled with no caller. Every such row read `agent:`, and all agents shared one refusal row per tool and hour. `undo_plan_change` recorded only `person:mcp` with no token name. A legacy token that passed a named agent's name and one bad argument wrote a refusal row into that named agent's journal. Each row now names the token that made the call, and `agent:invalid` is used only when the legacy token passes a named agent's name. + +- **An investigation claim's later calls are now tied to the named token that made the claim.** ([#6738]) - Before, `submit_investigation_report`, claim renewal and `get_investigation_evidence` checked only the `claim_id`. Any named token that presented another token's claim id could act on it. The legacy token could do the same under a named token's claim. These calls now require the token that made the claim. + +- **Plan guide drop answers now follow `mcp.dataDetail`, and forcing or unforcing a Query Store plan honors the excluded database list.** ([#6737]) - Before, `drop_plan_guide` returned the guide's batch text and hints as written, even with `mcp.dataDetail` set to `maskLiterals` or `metadataOnly`. The same text reached the journal. Now `module_or_batch` and `hints` are masked or withheld like other statement text. Also, `force_query_store_plan` and `unforce_query_store_plan`, and the force Undo, never checked a server's excluded databases. They now refuse there like the other plan tools. + +- **Choosing the web dashboard option in the Darling MSI now makes a web token, so the dashboard starts.** ([#6736]) - Before, the installer wrote `web.enabled: true` with no token. The web host refuses to start without a token, so the dashboard never started and the installer's last step gave up without saying so. The installer now makes a random token and protects it. The dialog no longer says anyone signed in can open the dashboard without a password. + +- **A server action switch no longer turns on for an Azure SQL target whose tool always refuses the action.** ([#6727]) - Before, the switch screens showed "on" and "valid" for an action that failed at every call on Azure SQL Database or Managed Instance. The switch now checks the stored engine edition and refuses to turn on an action the target cannot run. + +- **A generic webhook can now close an alert, and a PagerDuty resolve now closes the incident the trigger opened.** ([#6718], [#6723]) - The generic webhook has a new `{{status}}` token. It is `firing` on an alert and `resolved` on a resolution. A resolution now carries the same dedup key as the fire, so a receiver can pair the two posts. For PagerDuty, the resolve used a key from a different set of incidents than the trigger. On some alerts the wrong incident closed and the right one kept paging. The resolve now sends the key the trigger sent. + +- **Darling now copies the generic webhook, PagerDuty and send-resolutions settings from darling.json on its first start.** ([#6715]) - Before, the first start copied only the email, Teams and Slack settings into the store. The store won, so the file's generic webhook, PagerDuty and send-resolutions keys never took effect and nothing said so. + +- **Darling on plain PostgreSQL: the blocking and deadlock baselines stop at the purge horizon** ([#6706]) - On a store without TimescaleDB, the raw tables are purged at the retention time, but the days that count as covered reach back 30 days. With a retention under 30 days, days with no stored events counted as quiet. At 7 days retention about 23 of 30 days read as quiet. The mean fell about 77 percent, and normal blocking or deadlocks flagged as anomalies. The baselines now stop at the purge horizon. + +- **Alert texts use the right word for a count of one** ([#6700], [#6703]) - Alert texts printed counts like 1 source(s), 1 checkpoint(s) and 1 mute rule(s) have been. They now read 1 source and 1 checkpoint, and 1 mute rule has been, with the plural form for other counts. This covers the e-mail, Slack and other routes, the alert history and the MCP alert tools. Alerts that are already stored keep their old text. + +- **ANOMALY_WRITE_LATENCY is scored against a write latency baseline** ([#6696]) - The write latency gate used the read latency baseline. Take a server whose reads sit near 1 ms with a narrow spread. Any ordinary write window of 10 ms or more scored far above that baseline. One store saw 129 alerts and 16 investigation requests in 14 days, and every one was normal nightly writes. The gate now uses a baseline built from write latency. This applies to Lite and Darling. + +- **Chart text keeps its size at high Windows display scaling** ([#6678]) - In Lite and the Darling viewer, chart labels were drawn at 40 percent of their size at 250 percent display scaling. Charts now take the display scale of their window, and they follow when the window moves to a screen with another scale. + +- **Darling's Query Store reads no longer list the monitor's own statement or statements from dropped databases** ([#6654], [#6659]) - The get_query_store_regressions tool and the viewer listed the monitor's own statement and queries from databases that the server had dropped. Dropped databases also used up the row limit. These are now left out of the regressions read and of the other ranked Query Store reads, and the read names the databases it left out. + +- **Index Analysis no longer shows two banners that contradict each other, and two Settings and plan card labels are corrected** ([#6653]) - In the Darling viewer, Index Analysis showed the uptime under 14 days banner next to the dedupe-only banner. The first says unused index findings may be premature and the second says unused indexes were not flagged. With dedupe-only in effect, only the dedupe-only banner shows now. The get_finops index analysis notes follow the same rule. The help text for Capture execution plans and Query Store history backfill now sits with the matching settings. The estimated plan card is titled for what it holds instead of Predicted Runtime. + +- **The Darling viewer charts and grids stay readable on a 1366x768 screen** ([#6652]) - Before, stacked charts got a plot a few pixels tall, long left axis titles were cut at both ends and two wide grids, Query Store Regressions and Collection Health, squeezed their columns to slivers. Charts now keep a minimum height and the page scrolls. The grids keep their column widths. + +- **Web dashboard pages say MCP field names and raw collector counts in plain words** ([#6649]) - Notes written for MCP callers reached the web pages with field names that a person cannot act on, such as (see databases_left_out), baseline_start and latest_memory_mb, and raw key=value collector counts. The web pages now say these in words. MCP clients see the same text as before. + +- **The right-sized verdict sentence says what decided the verdict** ([#6646]) - A right-sized verdict also comes from a CPU average under 15 percent with one sample at 40 percent or more. It also comes from a memory grant use of 50 percent or more. The old fixed sentence said CPU was moderately loaded and memory was well used, which contradicted the numbers. The sentence now names the test that decided the verdict. + +- **A parallel query that waits on itself is no longer counted as blocking** ([#6645], [#6690]) - The threads of a parallel query can write blocked process reports where the blocked and blocking session are the same. Before, these counted in the wait counts, the head blocker count, the blocking chain and the blocking anomaly count. Now they are left out. The Darling blocking baseline leaves them out too, so it is compared with the same kind of window. Before, a server with many of these waits had a baseline that read too high. A real rise in blocking could stay under the anomaly line. Lite already did this for its baseline. + +- **A store that the operator brings now works for every MCP tool and web page that takes a server name** ([#6630]) - The MCP and web hosts opened the store with the connection string exactly as darling.json gives it, without the collect and config search path. On a database whose search path could not be set, every MCP tool that takes a server name failed with error 42P01. Web reads failed the same way. The hosts now add the search path, as the worker already did. The CLI and the viewer connections do too. + +- **Darling logs a usable web dashboard and MCP address when it listens on a specific IPv6 address** ([#6609]) - Before, a specific IPv6 listen address was logged without brackets, for example http://fd00::5:5150/, and a browser cannot open that. Now the address is logged in brackets. The installer ready message uses the same address, so it is correct too. + +- **Darling Query Store query history now reports a plan whose force was removed as REMOVED.** ([#6598]) - Before, a plan that was forced when sampled showed `is_forced_plan: true` with no forced state and an empty `forced_plans` list. An agent needed a second call to `get_forced_plans` to learn the force was gone. Now the plan shows `forced_state: "REMOVED"` and the removed force appears in `forced_plans`. A standing force never drops out of the list because of a removed one. + +- **The Darling install script registers the service path in quotes** ([#6597]) - Before, install-darling.ps1 registered the service path without quotes, so sc qc showed a bare path with spaces. The MSI registers it in quotes. The script now registers the quoted path, for both a new service and an in-place change. + +- **An agent that holds the live lease gets its claim_id back when it claims again** ([#6576]) - Before, an agent that lost its claim_id could not get it back. A second claim_investigation_request answered already_claimed, and the request stayed locked until the 15 minute lease ended. Now, with a named agent token in Darling, the claim answers renewed with the existing claim_id and renews the lease. A different agent still gets already_claimed. Lite and the legacy token keep the old answer. + +- **Change Watch no longer counts log_reuse_wait_desc as a database configuration change** ([#6566]) - The log_reuse_wait_desc value changes by itself when a long transaction ends or a log backup runs. Before, that opened watches and investigation requests, for example a tempdb change from ACTIVE_TRANSACTION to NOTHING. Change Watch now skips it, as the analysis already does. get_database_config_changes still lists it. + +- **get_change_watches accepts state=all, sends each fact once, and can read one watch by watch_id** ([#6561], [#6591]) - Before, the tool answered state all when you left state out, but refused state=all as invalid. Now state=all means no filter. A closed watch also carried measures, not_measured and changes twice, so a request for 3 watches could return about 60 KB. Now each fact appears once. The new optional watch_id argument returns one watch in any state. An unknown id, text that is not a GUID, or an id from another server answers not_found. This is Darling only. + +- **A Darling Change Watch no longer calls a plan mix shift a regression** ([#6555]) - A query that runs a fast plan and a slow plan at the same time has an average duration that follows the mix of plans. Before, a shift in that mix showed as a slower query even when no plan got slower. Now the watch compares the after window at the plan mix of the before window. A plan that got slower on its own, or a new slow plan, still counts as a regression. The result notes say when the average moved only with the plan mix. This covers Query Store and plan cache measures. + +- **Query Store reads on a readable secondary say it is not collected, and why** ([#6554]) - The collectors skip every database on a readable secondary, so it has no Query Store rows. Before, get_forced_plans answered empty and get_query_store_top said Query Store is READ_ONLY. Now both answer not_collected and say that the server is a readable secondary. The message stays silent when query_store_replica is set for the server. + +- **The Client Timeouts alert leaves out SSMS IntelliSense's own cancels** ([#6552]) - Before, the alert counted every time SSMS IntelliSense cancelled its own metadata queries. Those events are now left out of the count that the alert judges. When only IntelliSense pushed a server over a threshold, the fire is recorded as muted and nothing is sent. get_client_timeouts still shows these events and marks them as excluded. + +- **Change Watch requests get their own family, skip replicated plan changes, and name the database** ([#6551]) - Before, a Change Watch request fell into the other family with custom and external alerts, and it spent the hourly limit of the performance route. A forced plan on a readable secondary was recorded again there, because its Query Store holds the primary's forced plans. The request detail also named query hashes without the database. Now the requests have a family of their own, a secondary skips replicated plan changes, and the detail names the database and where the hashes came from. + +- **Change Watch says whether a plan was forced by automatic plan correction** ([#6550]) - Before, a recorded plan force did not say who forced the plan. A watch with only automatic plan correction forcing and reverting plans opened an investigation request like a person's change. Now each plan force carries MANUAL, AUTO, NONE or unknown, and get_change_watches shows it. A watch with only AUTO changes opens no request. A change recorded before this reads as unknown. + +- **SQL Server's own cleanup statements are left out of regression targets, findings and Query Store reads** ([#6548]) - A regression of the change tracking cleanup statement could rank first in the regression_targets evidence and in the PLAN_REGRESSION finding. Those now skip change tracking cleanup, sp_flush_commit_table and sp_cdc_cleanup_change_table. A read such as select * from sys.change_tracking_tables is not skipped. The Darling Query Store reads that rank statements, get_query_store_regressions among them, leave these statements out too. Their filter also matches the change tracking cleanup text that SQL Server writes with brackets, which it did not match before. + +- **The brief keeps the request's only alert when its text is long** ([#6547]) - Before, if the first alert alone was longer than the 8,000 character budget of the alerts section, the section came out empty and the agent got no alert text and no metric. Now the brief keeps that alert and cuts its long text further. The metric, time, value and threshold are never cut. The truncated entry says shortened: true. This applies to Lite and Darling. + +- **Darling table tuning waits at most 5 seconds for a lock** ([#6539]) - Before, each ALTER TABLE SET statement could wait up to 300 seconds behind another operation that held a heavy lock, such as drop_chunks or decompress_chunk. That could stall a service start. Now each statement waits at most 5 seconds. On a timeout Darling logs one Information line naming the table and retries on the next pass. + +- **Darling investigation requests from analysis findings get the resources and jobs families, not other** ([#6536]) - Before, most analysis categories that a SQL Server run emits had no investigation family. Their requests got the family meant for custom and external alerts, so you could not tell them apart by family. Findings in the anomaly, cpu, memory, io and disk categories now map to the resources family, and jobs findings to the jobs family. The family sets which open request a new one joins, which tools the brief offers, and the family filter in list_investigation_requests. A request opened before the upgrade keeps its other family, so an incident in flight at the upgrade can briefly hold an other request and a resources request for the same server. The config, database_config, coverage, bad_actor, tempdb and waits categories and the PostgreSQL ones stay other. This applies to Lite as well, because both editions share the map. + +- **Lite asks again before it uses a saved password for a changed server** ([#6504], [#6559]) - Lite keeps one server list for every Windows user of the computer, but each user has their own saved password. Before, if a server's host changed, Lite went on sending that user's saved password to the new host. Now Lite remembers, for each Windows user, the settings each server was saved with, and it asks you to confirm before it uses a saved credential with changed settings. In the Edit Server dialog, Test now asks one question and names the Query Store replica when you typed one. It no longer asks a second time after you answered Yes, and it asks nothing when the replica box is empty. + +- **Lite clears the Blocking and Deadlocks strips when the window has no events** ([#6482]) - Before, the strips kept the bars from the previous window while the grid below said there were no events. Now each strip clears and shows "No blocked process reports in the selected time window." or "No deadlocks in the selected time window." + +- **The Darling installer tells the truth when it stops, catches an unedited sample, and puts shortcuts where every user sees them** ([#6475]) - Before, it printed "Nothing was installed or changed" after it had already locked the folder's permissions. A darling.json that was an unedited copy of the sample passed on a rerun and installed. The Viewer shortcuts went to the Desktop of the elevated account, which is not always the person's. Now the sample check runs before the lock, the stop text says what is true, and the shortcuts are made for all users. + +- **The investigation brief lists the arguments that submit_investigation_report really takes** ([#6462], [#6546]) - Before, the brief's report contract listed root_cause_found as required, but the tool has no such argument, and it left out summary, which is required. The list now reads request_id, claim_id, report_format, verdict, root_cause, evidence and summary. The brief says the service sets root_cause_found from the verdict. For an anomaly request, the brief's next_calls now start with calls that fit the anomaly, such as get_file_io_trend for write latency and get_cpu_utilization for a CPU spike. This applies to Lite and Darling. + +- **Darling builds all three large start-path indexes during the first start of an empty store** ([#6460]) - Before, a new store built one of the three indexes on its first start and deferred the other two. About 30 seconds later the hourly pass logged two warnings that read like a fault, and a new store needed several restarts to be fully tuned. Now an empty table does not use the one-build budget, so the first start builds all three indexes and logs no warning. + +- **Lite no longer logs a notification_routes warning on its first start** ([#6458]) - On a first start, Lite read the notification_routes table before it had created the table and logged a WARN that read like a fault. Lite now creates its store first and then loads the routes. A table that goes missing later is still logged. + +- **Fleet-wide windows in the Darling viewer show times one way, and Azure SQL Database notes lead with what the engine lacks** ([#6457]) - The Notification Routes, Threshold Overrides and Known Patterns windows showed times in three different ways with no label, and Notification Routes applied a server's UTC offset to rows that belong to no server. Now all three show the same instant the same way, with the zone name after the time, for example 2026-07-01 10:07 UTC. Local mode uses this machine's zone and every other mode uses UTC. The "not collected" sentence on Azure SQL Database tabs such as Running Jobs, CPU Scheduler and Trace Flags now starts with what the engine lacks, not with the collector's name. + +- **Darling investigation event webhook posts now send the default User-Agent** ([#6456]) - Before, an investigation event post carried only the content-type and webhook signature headers, with no User-Agent. Now it sends the same default User-Agent that an alert post to a generic webhook URL already sends. Operator headers still belong to the alert channel only. + +- **Darling MCP write tools give honest statuses and clearer errors** ([#6455]) - The edit_server refusal for a host or connection change now says that the new settings must come with the password. The dismiss_alert_history and restore_alert_history tools answer dismissed or restored only when a row changed. They answer not_found for keys that name no row and unchanged for rows already in the asked state. update_alert_settings names the cooldown delivery.cooldown_minutes in updated_fields, whether the caller sent that or the email_cooldown_minutes alias. assign_query_tag refuses a query_hash that is not 0x plus 1 to 16 hex digits, or a decimal that does not fit an unsigned 64-bit number, as invalid. A call that leaves out a required argument now answers invalid and names the argument, in Darling and in Lite, including a call with no arguments at all. When a plan tool refuses a dry run that has no agent_action, the message says why a dry run needs the claim and whether the server action switch is on. The tool text and docs for custom alert rules now state the rule scope, which is all servers, a list of servers or a fleet tag. With no scope, the rule applies to every monitored server. + +- **Darling server admin tools are current at once and clean up after remove_server** ([#6454]) - Before, list_servers could show an edit or a removal 40 to 60 seconds late. Now it reads the server definition and is current at once. remove_server now also clears that server's collector schedule overrides and run times, which would have come back when you added the server again. The monthly cost of a server can now be cleared. + +- **Reads with nothing stored say empty when the collector ran clean** ([#6453]) - Before, the system_health reads and other reads with no stored rows answered unavailable and told you to check collection health, while collection health called the same collector healthy. Now a read with no stored rows answers empty, a true negative, when the collector's newest run succeeded with no note. This covers the nine get_health_parser reads after a clean event_file read. It also covers get_collector_stall_probes, which no longer answers not_collected for an empty 7 day window. An idle query_stats collector, such as on a serverless Azure SQL Database, is no longer banded WARNING as regressed. + +- **The system_health collector keeps reading new events when the ring buffer is full** ([#6441], [#6544], [#6564]) - SQL Server cuts the ring buffer at about 4 MB and keeps the oldest events. Before, a busy server could store 0 rows and record success while new events sat unread. Lite and Darling now read the session's event_file target, and the ring buffer is the fallback. When the saved bookmark is in the current file, the read opens that file by its exact path, so it stays well inside Lite's 30 second command timeout. + +[#5506]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/5506 +[#5736]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/5736 +[#6384]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6384 +[#6385]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6385 +[#6386]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6386 +[#6387]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6387 +[#6388]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6388 +[#6389]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6389 +[#6390]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6390 +[#6392]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6392 +[#6393]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6393 +[#6394]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6394 +[#6395]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6395 +[#6396]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6396 +[#6397]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6397 +[#6398]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6398 +[#6399]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6399 +[#6400]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6400 +[#6401]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6401 +[#6402]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6402 +[#6403]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6403 +[#6409]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6409 +[#6410]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6410 +[#6411]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6411 +[#6412]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6412 +[#6413]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6413 +[#6416]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6416 +[#6417]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6417 +[#6418]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6418 +[#6419]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6419 +[#6420]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6420 +[#6422]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6422 +[#6429]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6429 +[#6430]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6430 +[#6441]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6441 +[#6453]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6453 +[#6454]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6454 +[#6455]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6455 +[#6456]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6456 +[#6457]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6457 +[#6458]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6458 +[#6459]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6459 +[#6460]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6460 +[#6462]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6462 +[#6468]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6468 +[#6469]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6469 +[#6470]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6470 +[#6471]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6471 +[#6472]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6472 +[#6473]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6473 +[#6474]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6474 +[#6475]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6475 +[#6476]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6476 +[#6478]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6478 +[#6480]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6480 +[#6482]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6482 +[#6504]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6504 +[#6507]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6507 +[#6536]: https://github.com/erikdarlingdata/PerformanceMonitor/pull/6536 +[#6539]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6539 +[#6542]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6542 +[#6544]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6544 +[#6546]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6546 +[#6547]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6547 +[#6548]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6548 +[#6550]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6550 +[#6551]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6551 +[#6552]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6552 +[#6553]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6553 +[#6554]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6554 +[#6555]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6555 +[#6557]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6557 +[#6559]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6559 +[#6560]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6560 +[#6561]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6561 +[#6564]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6564 +[#6565]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6565 +[#6566]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6566 +[#6569]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6569 +[#6576]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6576 +[#6581]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6581 +[#6583]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6583 +[#6589]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6589 +[#6591]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6591 +[#6596]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6596 +[#6597]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6597 +[#6598]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6598 +[#6600]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6600 +[#6609]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6609 +[#6614]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6614 +[#6622]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6622 +[#6630]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6630 +[#6633]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6633 +[#6637]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6637 +[#6640]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6640 +[#6645]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6645 +[#6646]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6646 +[#6647]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6647 +[#6648]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6648 +[#6649]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6649 +[#6650]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6650 +[#6651]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6651 +[#6652]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6652 +[#6653]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6653 +[#6654]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6654 +[#6659]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6659 +[#6678]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6678 +[#6690]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6690 +[#6696]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6696 +[#6700]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6700 +[#6703]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6703 +[#6706]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6706 +[#6713]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6713 +[#6715]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6715 +[#6718]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6718 +[#6723]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6723 +[#6724]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6724 +[#6727]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6727 +[#6729]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6729 +[#6736]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6736 +[#6737]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6737 +[#6738]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6738 +[#6740]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6740 +[#6741]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6741 +[#6743]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6743 +[#6745]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6745 +[#6746]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6746 +[#6747]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6747 +[#6748]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6748 +[#6749]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6749 +[#6750]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6750 +[#6751]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6751 +[#6752]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6752 +[#6755]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6755 +[#6756]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6756 +[#6757]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6757 +[#6758]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6758 +[#6759]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6759 +[#6760]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6760 +[#6761]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6761 +[#6764]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6764 +[#6766]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6766 +[#6768]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6768 +[#6771]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6771 +[#6773]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6773 +[#6778]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6778 +[#6781]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6781 +[#6787]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6787 +[#6791]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6791 +[#6793]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6793 +[#6794]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6794 +[#6795]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6795 +[#6798]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6798 +[#6800]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6800 +[#6803]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6803 +[#6804]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6804 +[#6807]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6807 +[#6808]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6808 +[#6809]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6809 +[#6821]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6821 +[#6823]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6823 +[#6827]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6827 +[#6828]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6828 +[#6829]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6829 +[#6830]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6830 +[#6831]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6831 +[#6832]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6832 +[#6833]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6833 +[#6834]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6834 +[#6836]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6836 +[#6840]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6840 +[#6849]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6849 +[#6850]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6850 +[#6853]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6853 +[#6856]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6856 +[#6858]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6858 +[#6859]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6859 +[#6860]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6860 +[#6861]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6861 +[#6865]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6865 +[#6866]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6866 +[#6868]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6868 +[#6869]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6869 +[#6873]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6873 +[#6874]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6874 +[#6875]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6875 +[#6876]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6876 +[#6877]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6877 +[#6878]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6878 +[#6886]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6886 +[#6888]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6888 +[#6889]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6889 +[#6893]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6893 +[#6894]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6894 +[#6896]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6896 +[#6897]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6897 +[#6901]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6901 +[#6902]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6902 +[#6903]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6903 +[#6906]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6906 +[#6907]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6907 +[#6908]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6908 +[#6912]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6912 +[#6915]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6915 +[#6917]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6917 +[#6919]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6919 +[#6920]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6920 +[#6925]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6925 +[#6926]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6926 +[#6927]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6927 +[#6928]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6928 +[#6929]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6929 +[#6931]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6931 +[#6932]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6932 +[#6933]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6933 +[#6945]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6945 +[#6946]: https://github.com/erikdarlingdata/PerformanceMonitor/issues/6946 diff --git a/docs/darling/monitored-servers.md b/docs/darling/monitored-servers.md index 873bb02e14..38893a122e 100644 --- a/docs/darling/monitored-servers.md +++ b/docs/darling/monitored-servers.md @@ -106,23 +106,25 @@ Collectors that hit a permission error (SQL errors 229/297/300, plus 8189 from ` ### Which collectors run on which platform -Every collector declares its own applicability in code (`AppliesTo(CollectorTargetInfo)`), so this is not a hand-maintained per-collector list — the SQL Server collectors fall into seven groups, and a collector outside its supported platform is **skipped before it runs**, not failed and logged every cycle. +Every collector declares its own applicability in code (`AppliesTo(CollectorTargetInfo)`), so this is not a hand-maintained per-collector list — the SQL Server collectors fall into eight groups, and a collector outside its supported platform is **skipped before it runs**, not failed and logged every cycle. | Runs on | Collectors | Gate | |---|---|---| -| Everything | wait stats, CPU utilization, memory (stats/clerks/grants), file I/O, tempdb, latches, spinlocks, plan cache, session summary, plus blocking, deadlocks, blocked-process reports, DMV blocking snapshots, perfmon, query snapshots, procedure stats, index/object stats, long-query completions, client timeouts (`attention`), database config/scoped-config/size, server properties, session stats, waiting tasks | no gate | -| On-prem, Managed Instance, RDS — **not** Azure SQL DB | CPU scheduler stats, default trace events, memory pressure events, server config, system health events, trace flags, database states, Availability Group replica states, Availability Group database replica states | `!IsAzureSqlDb` | -| On-prem and Managed Instance, needs msdb | job history | `!IsAzureSqlDb && HasMsdbAccess` | -| On-prem and Managed Instance, needs msdb — **not** RDS | agent status, running jobs | `!IsAzureSqlDb && !IsAwsRds && HasMsdbAccess` | +| Everything | wait stats, CPU utilization, memory (stats/clerks/grants), file I/O, tempdb, latches, spinlocks, plan cache, session summary, plus blocking, deadlocks, blocked-process reports, DMV blocking snapshots, perfmon, query snapshots, procedure stats, index/object stats, long-query completions, client timeouts (`attention`), database config/scoped-config/size, server properties, session stats, waiting tasks, identity capacity (on Azure SQL Database it reads one database at a time), database protection (backups and CHECKDB, labelled by platform) | no gate | +| On-prem, Managed Instance, RDS — **not** Azure SQL DB | CPU scheduler stats, default trace events, memory pressure events, server config, system health events, trace flags, database states, Availability Group replica states, Availability Group database replica states, job history | `!IsAzureSqlDb` | +| On-prem and Managed Instance, **not** RDS | agent status, running jobs | `!IsAzureSqlDb && !IsAwsRds` | +| On-prem only, **not** Managed Instance, RDS or Azure SQL DB | Agent alerts | `!IsAzureSqlDb && !IsAwsRds && !IsAzureManagedInstance` | | SQL Server 2016+ (or any Azure flavour) | query stats, Query Store stats, Query Store health, Query Store forced plans | `SqlMajorVersion >= 13 \|\| IsAzureSqlDb \|\| IsAzureManagedInstance` | | SQL Server 2017+ (or any Azure flavour) | plan correction (automatic tuning recommendations) | `SqlMajorVersion >= 14 \|\| IsAzureSqlDb \|\| IsAzureManagedInstance` | | SQL Server 2019+ (or any Azure flavour) | persistent version store stats | `SqlMajorVersion >= 15 \|\| IsAzureSqlDb \|\| IsAzureManagedInstance` | +| SQL Server 2022+ (or any Azure flavour) | Query Store hints | `SqlMajorVersion >= 16 \|\| IsAzureSqlDb \|\| IsAzureManagedInstance` | Notes: -- **Azure SQL DB** is the most restricted target: the nine `!IsAzureSqlDb` collectors above, and job history, read server-scoped DMVs or on-disk artifacts that do not exist there, and the SQL Agent collectors have no Agent to read. Nothing about that is a permission problem, so it is not reported as one. -- **AWS RDS** blocks direct `msdb` job reads specifically; the rest of the SQL Agent surface is unaffected. -- **`HasMsdbAccess`** is probed per server at connect and is exactly `HAS_DBACCESS('msdb')` — *any* access to msdb, not a specific role or table grant. Losing msdb access later moves those collectors from running to skipped without an error storm. A login that can enter msdb but lacks `SELECT` on the job tables passes this probe and is caught one layer down as a `PERMISSIONS` skip instead. +- **Azure SQL DB** is the most restricted target: the ten `!IsAzureSqlDb` collectors above read server-scoped DMVs or on-disk artifacts that do not exist there, and the SQL Agent collectors have no Agent to read. Nothing about that is a permission problem, so it is not reported as one. +- **AWS RDS** refuses most `msdb` reads to its master user. Agent status, running jobs and Agent alerts do not run there. Job history still does. The database protection collector runs on RDS and labels its rows by platform. +- **Azure SQL Managed Instance** refuses `sp_add_alert`, so its `sysalerts` is always empty and the Agent alerts collector does not run there. Database protection shows backup and CHECKDB ages on Managed Instance and on Azure SQL Database, and never calls them overdue. +- **msdb access** is not a gate. A login that cannot read the msdb tables is not skipped up front. Its Agent collectors run, are denied, and log a `PERMISSIONS` row, which shows as `NO_PERMISSIONS` in Collection Health. A grant added later takes effect on the next cycle with no restart. - An unknown version (`SqlMajorVersion == 0`, i.e. detection has not completed yet) is treated as capable rather than skipped, so a collector is never silently dropped because a probe was slow. If a tab or column is empty and you expect data, check **Collection Health**: a collector skipped for platform reasons shows no runs at all, whereas one denied by permissions logs `PERMISSIONS` and is classified `NO_PERMISSIONS`. Those are different problems with different fixes — the first is expected on that platform, the second is a grant to add from the table above. diff --git a/docs/editions.md b/docs/editions.md index d42841055c..20a08d46c1 100644 --- a/docs/editions.md +++ b/docs/editions.md @@ -39,10 +39,10 @@ All editions include real-time alerts (email + webhooks), charts and graphs, Dar | Themes | Dark, Light and Cool Breeze, with per-color overrides | Dark, Light and Cool Breeze, with per-color overrides (viewer) | Dark, Light and Cool Breeze | | Web dashboard | Not available | Optional, off by default (port 5153) | Not available | | Portability | Single executable | Portable service + viewer zip (Windows), service tarball (Linux) | Server-bound | -| SQL Server collectors | More than 40 (the long-running-query trace is opt-in) | Lite's set, plus a forced-plan collector, a Query Store hint collector and an identity column capacity collector | Its own set, installed on the target | +| SQL Server collectors | More than 40 (the long-running-query trace is opt-in) | Lite's set, plus a forced-plan collector, a Query Store hint collector, an identity column capacity collector, a database protection collector (backups and CHECKDB) and an Agent alerts collector | Its own set, installed on the target | | PostgreSQL collectors | None | More than 25 | None | | Agent investigations (your own AI agent picks up an alert and reports) | Level 1: the agent reads and reports | Level 1 to 3: reports, plus agent-made alert changes and server actions, each behind its own switch | Not available | -| Agent changes on a monitored server (force or unforce a Query Store plan, evict a cached plan, kill a session) | Not available | Yes, one switch per server and action, all off until you turn them on | Not available | +| Agent changes on a monitored server (force or unforce a Query Store plan, evict a cached plan, recompile a module, create or drop a plan guide, kill a session) | Not available | Yes, one switch per server and action, all off until you turn them on | Not available | | Query tags (name a group of queries and see its resource use) | Yes | Yes | Not available | | Notification routes limited to a server or a tag | Yes | Yes | Not available | | MCP server (LLM integration) | Built-in (more than 100 tools) | On request (more than 200 tools) | Built into Dashboard (more than 60 tools) | diff --git a/docs/lite-guide.md b/docs/lite-guide.md index 8a28327d07..0f6330b498 100644 --- a/docs/lite-guide.md +++ b/docs/lite-guide.md @@ -200,6 +200,14 @@ More than 40 collectors run on independent, configurable schedules (the long-run | database_scoped_config | On connect | Database-scoped configurations | | trace_flags | On connect | `DBCC TRACESTATUS` | -Darling runs these same collectors across a fleet of servers, plus `query_store_forced_plans`, which reads each database's forced plans, and `query_store_hints`, which reads each database's Query Store hints (SQL Server 2022 and later), and `identity_capacity`, which reads how full each database's identity columns are. Lite has none of these. Darling also runs more than 25 PostgreSQL collectors. See the [Darling collector reference](../Darling/README.md). +Darling runs these same collectors across a fleet of servers. It adds five more that Lite does not have: + +- `query_store_forced_plans` reads each database's forced plans. +- `query_store_hints` reads each database's Query Store hints (SQL Server 2022 and later). +- `identity_capacity` reads how full each database's identity columns are. +- `database_protection` reads the last good CHECKDB and the last full and log backup of each database. +- `agent_alerts` reads the SQL Server Agent alerts and the operators they notify. + +Darling also runs more than 25 PostgreSQL collectors. See the [Darling collector reference](../Darling/README.md). The Extended Events sessions that Lite creates on a monitored server, and how to remove them, are on their own page: [The Extended Events Sessions Lite Creates](lite-extended-events.md). diff --git a/docs/tabs.md b/docs/tabs.md index 61ccbc1ea7..5762984361 100644 --- a/docs/tabs.md +++ b/docs/tabs.md @@ -91,7 +91,7 @@ Each per-server tab has these inner tabs (**Session Stats**, **Configuration Cha | **Queries** | Sub-tabs over the last 24 hours — **Performance Trends** (a 2×2 of per-second trend charts: query duration, procedure duration, Query Store duration, execution count), **Active Queries** (the ~26-column filterable snapshot grid of captured running queries with a time-range slicer, a **Latest Snapshot** button that re-reads the newest stored capture, and per-row Estimated / Actual plan buttons that open the stored plan in the Plan Viewer), **Top Queries by Duration** (the full query-stats grid with in-grid bar cells for executions/CPU/duration/reads and a CPU-by-database breakdown), **Top Procedures by Duration**, **Query Store by Duration**, **Query Store Regressions**, **Query Store Clutter** (#3797 — which databases make this server's Query Store catalog expensive: per database the collector's read cost, plan churn and options row with the verdict and its reasons, a readable secondary carried as a row with the architectural reason on it rather than filtered out, and the per-server `QDS_*` / memory-clerk overhead proxy in a block of its own; select a row for the recommendation), **Plan Corrections**, and **Query Heatmap** (query counts per 5-minute bin × per-execution magnitude bucket, by a chosen metric; right-click a cell to drill into Active Queries for that window) — the three per-source grids each carry a time-range slicer (drag to narrow the window) and a shared **Compare** control that overlays the current window against a baseline period (yesterday, last week, or same day last week), flagging new and vanished queries | | **Plan Viewer** | Hosts execution plans as closable sub-tabs (the shared plan-viewer control, the same one Lite and the Dashboard use). Right-click a **Top Queries** or **Query Store** row and choose **View Plan** to open the plan the service captured for it (`query_stats.query_plan_xml` / `query_store_stats.query_plan_text`); Top Queries rows also carry a **Query Plan** column whose Download button saves the stored plan as a `.sqlplan` file (enabled only when a plan was captured). Top Procedures and the blocking / deadlock reports deliberately do **not** surface a plan here — procedure plans aren't stored, and blocked-process / deadlock rows carry only a `sql_handle` (not plan XML); resolving either to a plan needs a live SQL connection the viewer never makes. "Get Actual Plan" (a live re-execution) is likewise out | | **CPU** | Raw per-sample CPU utilization (SQL Server vs other processes) over the last 24 hours — every ring-buffer sample, full-bleed as two series; the Overview's CPU lane plots the same raw samples compactly (SQL vs SQL+other Total) with a baseline | -| **Memory** | Sub-tabs over the last 24 hours — **Overview** (a summary strip of physical / SQL Server / target / buffer pool / plan cache / page-file memory plus the system memory state and model, over a Total-vs-Target-vs-Buffer-Pool memory trend with a memory-grants overlay), **Memory Clerks** (a searchable clerk-type picker — top-5 default, checked-to-top, clear-only-the-filtered — beside a per-clerk memory trend for the checked clerks with a non-buffer-pool total and top-clerk summary), **Memory Grants** (per-resource-pool grant sizing — available / granted / used MB — and activity — grantees / waiters / timeouts / forced grants), and **Memory Pressure Events** (hour-bucketed stacked bars of `RING_BUFFER_RESOURCE_MONITOR` pressure, SQL Server vs OS, medium vs severe) | +| **Memory** | Sub-tabs over the last 24 hours — **Overview** (a summary strip of physical / SQL Server / target / buffer pool / plan cache / page-file memory plus the system memory state and model, over a Total-vs-Target-vs-Buffer-Pool memory trend with a memory-grants overlay), **Memory Clerks** (a searchable clerk-type picker — top-5 default, checked-to-top, clear-only-the-filtered — beside a per-clerk memory trend for the checked clerks with a non-buffer-pool total and top-clerk summary), **Memory Grants** (per-resource-pool grant sizing — available / granted / used MB — and activity — grantees / waiters / timeouts / forced grants), **Memory Pressure Events** (hour-bucketed stacked bars of `RING_BUFFER_RESOURCE_MONITOR` pressure, SQL Server vs OS, medium vs severe), **Resource Semaphore** (resource semaphore pressure over the window, and the newest resource semaphore snapshot), and **Plan Cache** (the plan cache by type at the newest snapshot) | | **File I/O** | Sub-tabs over the last 24 hours — **Latency** (per-file read and write latency, with a dashed queued-I/O overlay) and **Throughput** (per-file read and write MB/s) — the top 10 files by activity | | **tempdb** | Stacked charts over the last 24 hours — space usage (user / internal objects / version store), total allocated size, and per-file I/O latency | | **Blocking** | Sub-tabs over the last 24 hours — **Trends** (lock-wait rate, blocking incidents, deadlocks), **Current Waits** (waiting-task duration by wait type, blocked sessions by database), **Blocked Process Reports** (the full ~25-column filterable grid — XE reports preferred with the always-on DMV blocking snapshot merged in as fallback, each row badged with its source, a time-range slicer, per-row report-XML save, and long-block highlighting; double-click or right-click **View Block Chain** to reconstruct and draw the blocking chain the row belongs to), and **Deadlocks** (one filterable row per process parsed from each deadlock graph, a slicer, per-row graph-XML save; double-click or right-click **View Deadlock Graph** to draw the deadlock graph) | @@ -99,14 +99,14 @@ Each per-server tab has these inner tabs (**Session Stats**, **Configuration Cha | **Running Jobs** | Latest snapshot of currently-running SQL Agent jobs — start time, current vs average vs p95 duration, % of average, and a highlighted row when a job is running past its p95 (a store-derived banner appears when the service's login lacks msdb access) | | **Configuration** | Column-filterable snapshot grids of the server's latest capture — server configuration (`sys.configurations`), database configuration (28 columns of `sys.databases`), database-scoped configuration, and trace flags. The web page also shows two Identity Capacity panels. They hold the columns above 10 percent and each database's scan state, as the Identity Capacity tab does. It also shows the SQL Server Agent alerts and the gaps in them here, and a Health Checks panel with the last full backup, log backup and CHECKDB of each database, overdue ones first | | **Daily Summary** | A one-row roll-up of the selected day (default today, UTC, with a date picker) — total wait time, the top wait type, distinct query count, deadlock / blocking-event / high-CPU-sample counts, collector errors, and an overall health band | -| **Collection Health** | Sub-tabs — **Health Summary** (a 7-day per-collector roll-up: run / success / error counts, failure rate, average duration, last success / run / error, and a health band of HEALTHY / WARNING / STALE / FAILING / NEVER_RUN / NO_PERMISSIONS / EXTENSION_MISSING — double-click a collector to open its full run history), **Collection Log** (the recent run log with per-run SQL and store-write timings and row counts), and **Duration Trends** (a per-collector success-duration scatter) | +| **Collection Health** | Sub-tabs — **Health Summary** (a 7-day per-collector roll-up: run / success / error counts, failure rate, average duration, last success / run / error, and a health band of HEALTHY / WARNING / STALE / FAILING / NEVER_RUN / NO_PERMISSIONS / EXTENSION_MISSING — double-click a collector to open its full run history), **Collection Log** (the recent run log with per-run SQL and store-write timings and row counts), **Duration Trends** (a per-collector success-duration scatter), and **Sweep Pressure** (SQL Server only: the sweep verdict, busy percent, peak cycle and peak risk, and the three heaviest collectors, over the last 7 days whatever the time range is) | The aggregate tabs — **Overview** and **Alerts** span every server; **Recommendations** has its own server selector, independent of the sidebar. **Job History** and **FinOps** are not described below: | Tab | Contents | |---|---| | **Overview** | A card per registered server (all servers, not the sidebar selection): server name + status dot, CPU (total non-idle with the SQL-only number alongside), memory, blocking and deadlock counts over the last hour, and last-collection time, each colour-banded (CPU ≥ 80% red / ≥ 50% amber / green; blocking and deadlocks red-or-amber when present) with a red **Offline** overlay. Status is derived from **collection freshness** — the newest `collection_log` age — rather than a live ping (the viewer never connects to the monitored servers): fresh is Online, older than twice the fastest collector's one-minute cadence is a Warning, and no recent collection is Offline. **Double-click a card** to open that server's tab. Refreshes every 30 seconds | -| **Recommendations** | The latest analysis run's findings for the tab's **own selected server** — a server selector independent of the sidebar, a Refresh button, and a status line showing the last analysis time — re-skinned to Lite's advise-only **card** design: a scrollable list of collapsible **incident** sections, each holding severity-banded cards (a severity badge, the affected `[database]`, the title, and the advice). Every card offers **Ask AI** (copies an MCP investigation prompt referencing `analyze_server` / `get_analysis_findings`); a card whose stored remediation carries a copy-paste statement also offers **Copy fix** (copies the suggested T-SQL). Advise-only — the viewer never applies anything, and there is no mute affordance here (alert muting lives on the Alerts surface). There is no in-app "Generate now": the service runs analysis on its own 30-minute cadence, so the status line surfaces the last analysis time instead | +| **Recommendations** | The latest analysis run's findings for the tab's **own selected server** — a server selector independent of the sidebar, a Refresh button, and a status line showing the last analysis time — re-skinned to Lite's advise-only **card** design: a scrollable list of collapsible **incident** sections, each holding severity-banded cards (a severity badge, the affected `[database]`, the title, and the advice). Every card offers **Ask AI** (copies an MCP investigation prompt referencing `analyze_server` / `get_analysis_findings`); a card whose stored remediation carries a copy-paste statement also offers **Copy fix** (copies the suggested T-SQL). Advise-only — the viewer never applies anything, and there is no mute affordance here (alert muting lives on the Alerts surface). A **Generate now** button asks the service to run an analysis at once, and the service also runs one on its own 30-minute cadence | | **Alerts** | The full alert history from `config_alert_log` across **all servers** (newest first, selectable time range), with a Server column and a Server filter. Double-click a row (or **View Details**) for a modal detail window showing the alert's stored detail and structured advice / remediation / drill-down from its dedup-fingerprint context. **Dismiss Selected / Dismiss All** hide alerts from the view (a durable `dismissed` flag on `config_alert_log`); column filters, Copy Cell/Row/All, and Export to CSV match Lite's grid. Right-click to **Mute This Alert** or **Mute Similar** (metric-only), and a **Manage Mute Rules** button opens the mute-rule editor | The Darling web dashboard has these pages in its sidebar: diff --git a/tools/changelog/archive-census.txt b/tools/changelog/archive-census.txt index b3f9b3c748..792d22aa3b 100644 --- a/tools/changelog/archive-census.txt +++ b/tools/changelog/archive-census.txt @@ -10,6 +10,7 @@ # fails CI. It is the durable half of the proof; `roundtrip` is the whole-document half and # needs the pre-split revision to compare against. +3.12.0 188 5990b2d01ed6de1e7f9247a0aeb225ef96fdd35aed4ac6f12fc4bca47a4e0b3b 3.11.0 316 401ebf89639bdb101f0b0a440bbb0c7600e8ee68fb2c17d2454850cf3ffa8e44 3.10.0 295 ef28f41a6dd880e58385f22457d758b44db9b24991ebf3f832629e7792ddaa30 3.9.0 763 1eee70db2f8bde116172c6c15edf453cdc5e5579323dc046a1ec1ebacdf7a8ce