-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-server-health-check.sql
More file actions
71 lines (57 loc) · 1.67 KB
/
basic-server-health-check.sql
File metadata and controls
71 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Script: basic-server-health-check.sql
Author: Misty Collins
Purpose: Identify common SQL Server operational risks
Notes: Read-only diagnostic queries
*/
--------------------------------------------------
-- SQL Server Version
--------------------------------------------------
SELECT
@@SERVERNAME AS ServerName,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('ProductVersion') AS Version,
SERVERPROPERTY('ProductLevel') AS PatchLevel;
--------------------------------------------------
-- Databases not backed up recently
--------------------------------------------------
SELECT
d.name AS database_name,
MAX(b.backup_finish_date) AS last_backup
FROM sys.databases d
LEFT JOIN msdb.dbo.backupset b
ON d.name = b.database_name
AND b.type = 'D'
WHERE d.database_id > 4
GROUP BY d.name
ORDER BY last_backup;
--------------------------------------------------
-- SQL Agent jobs that failed recently
--------------------------------------------------
SELECT
j.name AS job_name,
h.run_date,
h.run_time,
h.run_status
FROM msdb.dbo.sysjobhistory h
JOIN msdb.dbo.sysjobs j
ON h.job_id = j.job_id
WHERE h.run_status = 0
AND h.step_id = 0
ORDER BY h.run_date DESC;
--------------------------------------------------
-- Databases with AUTO_SHRINK enabled
--------------------------------------------------
SELECT
name,
is_auto_shrink_on
FROM sys.databases
WHERE is_auto_shrink_on = 1;
--------------------------------------------------
-- Databases with AUTO_CLOSE enabled
--------------------------------------------------
SELECT
name,
is_auto_close_on
FROM sys.databases
WHERE is_auto_close_on = 1;