Backups
Hardware fails: imagine a faulty disk that leaves the database files corrupted. People make mistakes: imagine forgetting a WHERE clause and updating or deleting every record in a table. We automate monitoring of backups, and of disks running low on free space, to minimize data loss and downtime. And we test restores, because a backup you have never restored is only a hope.
Indexes
Used incorrectly, indexes can be counter-productive and degrade performance, and over time they fragment and become increasingly inefficient. We automate finding the indexes that hurt performance and the ones that would benefit from defragmentation.
Jobs
Jobs automate repetitive tasks such as checking database integrity, running queries or shrinking files on a schedule. We monitor them and send notifications when there are problems, or simply to report their status.
Long-running queries
In our experience, databases support a small, finite number of connections. They are precious resources that must be protected from accidental misuse, so we monitor for long-running queries that should be optimized to keep the database available and scalable.
Access and protection
Databases are what attackers are usually after. We review who and what can connect, apply least-privilege access, encrypt data at rest and in transit, and make sure suspicious activity gets noticed.
Example: a C# worker service
This worker service connects to SQL Server and Azure SQL databases to retrieve index fragmentation, then fixes each index according to how fragmented it is.
•
30% fragmented or more: rebuild the index (ALTER INDEX … REBUILD), one partition at a time if it is partitioned.
•
10% fragmented or more: reorganize the index (ALTER INDEX … REORGANIZE), one partition at a time if it is partitioned.
SELECT DISTINCT
SCHEMA_NAME(o.schema_id) AS SchemaName
,OBJECT_NAME(o.object_id) AS TableName
,i.[name] AS IndexName
,CASE WHEN ISNULL(ps.function_id,1) = 1 THEN 'NO' ELSE 'YES' END AS IsPartitioned
,p.partition_number AS PartitionNumber
,dmv.Avg_Fragmentation_In_Percent AS AverageFragmentationInPercent
FROM sys.partitions AS p WITH (NOLOCK)
INNER JOIN sys.indexes AS i WITH (NOLOCK)
ON i.object_id = p.object_id
AND i.index_id = p.index_id
INNER JOIN sys.objects AS o WITH (NOLOCK)
ON o.object_id = i.object_id
INNER JOIN sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, N'LIMITED') dmv
ON dmv.object_id = i.object_id
AND dmv.index_id = i.index_id
AND dmv.partition_number = p.partition_number
LEFT JOIN sys.data_spaces AS ds WITH (NOLOCK)
ON ds.data_space_id = i.data_space_id
LEFT JOIN sys.partition_schemes AS ps WITH (NOLOCK)
ON ps.data_space_id = ds.data_space_id
WHERE OBJECTPROPERTY(p.object_id, 'IsMSShipped') = 0;