Category: Maintenance

  • DBA Scripts: Collect Blocking and Deadlock Events

    ,

    Blocking and Deadlocks, Recorded as They Happen When someone reports that the app was slow ten minutes ago, the blocking has usually cleared and the evidence has gone with it. Get Blocking Sessions and sys.dm_exec_requests only show what is blocking now, and deadlock reports sit in the system_health ring buffer only until newer events push…

  • DBA Scripts: Generate Index Maintenance Jobs

    ,

    A Readable Generator for Index Rebuilds and Statistics Updates If you’re already running Ola Hallengren’s maintenance solution, this won’t replace it, but the approach here might still be useful: a small, readable T-SQL generator that builds an index maintenance job framework as plain sp_add_job / sp_add_jobstep DDL you can review line by line before you…

  • DBA Scripts: Get SQL Agent Job Failure Summary

    ,

    A job has failed and the notification, if you got one at all, says “The job failed” and nothing else. The real error is sitting in msdb job history for every failed step, but nobody opens job history until they already suspect something, so a job can fail quietly every night for a week. This…

  • DBA Scripts: Get Maintenance Job Status

    ,

    A maintenance job that’s silently failing is one of the more dangerous states a SQL Server instance can be in, because everything looks normal from the outside. The database is online, queries run fine, and the index maintenance or stats update job that’s supposed to be keeping things healthy has been failing every night for…

  • DBA Scripts: Get Agent Alerts and Operators

    ,

    A SQL Server can raise a severity 19-25 error, the fatal, “something is genuinely broken” tier, corruption, out-of-resource conditions, hardware faults, and if there’s no alert configured for that severity, nothing happens. No on-call alert, no email, no Slack message. The error sits in the error log where it will be found eventually, usually during…

  • DBA Scripts: Get Index Design Issues

    ,

    Most index problems aren’t about a single bad index, they’re about a table’s index design as a whole drifting out of shape over time. A table that accumulates 25 indexes because nobody ever removed the old ones. A composite key that grew column by column until it’s wider than SQL Server is comfortable with. A…

  • DBA Scripts: Get Duplicate Indexes

    ,

    Indexes accumulate the same way clutter does: one developer adds an index to fix a slow query, a colleague adds a near-identical one three months later because the first one wasn’t obvious from the name, and nobody ever goes back to check whether both are pulling their weight. Two indexes on exactly the same columns…

  • DBA Scripts: Get Unused Indexes

    ,

    Every non-clustered index has to be maintained by SQL Server on every INSERT, UPDATE, and DELETE against the table. A table with 12 non-clustered indexes means 12 index updates for every row changed. Some of those indexes earn their keep by serving real queries. Others haven’t been read by a single query since the last…

  • When Shrinking Temp DB Just Won’t Shrink

    This is broken. You run DBCC SHRINKFILE on the Temp DB data files, maybe throw in a CHECKPOINT for good measure, and nothing moves. The files sit there stubbornly taking up space you need back. I am not in the habit of shrinking databases. It fragments files and usually just creates more work later. But…

  • DBA Scripts: Get Heaps

    ,

    Heaps in SQL Server Explained A surprising amount of SQL Server performance pain comes from tables that were never given a clustered index. These heaps often start life as quick prototypes, staging tables, or legacy leftovers, but as data grows, they quietly become one of the most consistent sources of wasted IO inside a production…