A DBA should be able to review every statement SQLInsight sends to a monitored server before granting it access. "SQL Scripts/<rule-id>.sql" holds, per rule (82 built-in, 16 community), a Danish header (what and why, how C# judges the data, thresholds with config keys, severity, exact GRANTs, versions, collector file and member) and the collector's SQL verbatim, every version variant as its own batch. "_collectors/<Collector>.sql" holds each collector's queries once. The only statement that is not strictly read-only is documented in the scripts: the deadlock collector's session temp table (#system_health). Inline SQL in the collectors moved to internal constants and Build*Sql methods (no text changed), so SqlScriptTests can check that the scripts still contain the SQL the code sends, that every rule has a script, that every collector query is registered, and that nothing writes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
145 lines
7.8 KiB
Transact-SQL
145 lines
7.8 KiB
Transact-SQL
-- ===================================================================================================================
|
|
-- SQLI-CFG-001: max server memory er ikke sat
|
|
-- ===================================================================================================================
|
|
-- Regel-id: SQLI-CFG-001
|
|
-- Titel: max server memory er ikke sat
|
|
-- Alvor: High
|
|
-- Versioner: Alle (SQL Server 2000 og nyere). Ikke relevant på Azure SQL Managed Instance.
|
|
--
|
|
-- Hvad tjekkes, og hvorfor:
|
|
-- Om 'max server memory (MB)' står på standardværdien, så SQL Server kan tage al hukommelse og presse Windows til
|
|
-- paging.
|
|
--
|
|
-- Vurdering (sker i C# ud fra de indsamlede data, ikke i SQL'en, medmindre andet er nævnt):
|
|
-- Fund hvis value_in_use for 'max server memory (MB)' (ConfigurationCollector) er >= 2147483647. Den anbefalede
|
|
-- værdi i fundet beregnes af fysisk hukommelse (ServerCollector): max(fysisk / 2, fysisk - max(4096 MB, 10 % af
|
|
-- fysisk)).
|
|
--
|
|
-- Grænseværdier (konfigurationsnøgle i agentens appsettings.json og standardværdi):
|
|
-- Standardværdien 2147483647 (int.MaxValue). Reserve til Windows: det største af 4096 MB og 10 %
|
|
-- (MemoryGuidance.Reserve, fast i koden).
|
|
--
|
|
-- Rettigheder til agentens login (se db/permissions/grant-least-privilege.sql; [agent] = agentens login):
|
|
-- GRANT VIEW SERVER STATE TO [agent]; -- SQL Server 2005-2019
|
|
-- GRANT VIEW SERVER PERFORMANCE STATE TO [agent]; -- SQL Server 2022+ (erstatter VIEW SERVER STATE)
|
|
-- GRANT VIEW SERVER SECURITY STATE TO [agent]; -- SQL Server 2022+
|
|
-- SQL Server 2000 har ikke VIEW SERVER STATE; se docs/legacy-versions.md (fx kræver DBCC SQLPERF(WAITSTATS) forhøjede rettigheder).
|
|
--
|
|
-- Data kommer fra (collector, fil : medlemmer, interval):
|
|
-- ConfigurationCollector
|
|
-- Fil: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs
|
|
-- Medlemmer: ConfigurationCollector.Sql2005, ConfigurationCollector.Sql2000
|
|
-- Interval: 15 min som standard (SQLInsight:CollectorIntervals:configuration)
|
|
-- Delt script: SQL Scripts/_collectors/ConfigurationCollector.sql
|
|
-- ServerCollector
|
|
-- Fil: src/SQLInsight.Collectors/Instance/ServerCollector.cs
|
|
-- Medlemmer: ServerCollector.BuildSql(version), Db.StartTimeSql(version), ServerCollector.Sql2000
|
|
-- Interval: 15 min som standard (SQLInsight:CollectorIntervals:server)
|
|
-- Delt script: SQL Scripts/_collectors/ServerCollector.sql
|
|
-- Regelkode: src/SQLInsight.Rules/Configuration/ConfigurationRules.cs : MaxServerMemoryDefaultRule.Evaluate
|
|
--
|
|
-- Read-only: Ja: kun SELECT samt xp_msver (læser versionsoplysninger), SET-sessionsindstillinger. Intet ændrer
|
|
-- data, indstillinger eller objekter.
|
|
-- Kørsel: Kør i SSMS som agentens login (eller et login med samme rettigheder). Hver variant er sin egen batch
|
|
-- (GO); en variant for en anden SQL Server-version end din kan fejle - det er forventet.
|
|
-- Per-database-forespørgsler er vist for databasen msdb, som findes overalt: ret navnet til den
|
|
-- database, du vil se.
|
|
-- ===================================================================================================================
|
|
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
-- Forbindelsen: Sessionsindstillinger, agenten sætter på hver forbindelse
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Variant: Alle versioner: sættes på hver forbindelse, agenten åbner
|
|
-- Kilde: SqlConnectionFactory.SessionSettings
|
|
-- Kode: src/SQLInsight.Connectivity/SqlConnectionFactory.cs : SqlConnectionFactory.SessionSettings
|
|
SET LOCK_TIMEOUT 5000; SET DEADLOCK_PRIORITY LOW; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
|
|
GO
|
|
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
-- ConfigurationCollector: sp_configure: konfigureret værdi og værdi i brug for alle serverindstillinger.
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Variant: SQL Server 2005 og nyere
|
|
-- Kilde: ConfigurationCollector.Sql2005
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs : ConfigurationCollector.Sql2005
|
|
SELECT name, CAST(value AS bigint), CAST(value_in_use AS bigint) FROM sys.configurations
|
|
GO
|
|
|
|
-- Variant: SQL Server 2000 (legacy ODBC-sti)
|
|
-- Kilde: ConfigurationCollector.Sql2000
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs : ConfigurationCollector.Sql2000
|
|
SELECT v.name, CAST(c.value AS bigint), CAST(r.value AS bigint)
|
|
FROM master.dbo.spt_values v
|
|
JOIN master.dbo.sysconfigures c ON c.config = v.number
|
|
JOIN master.dbo.syscurconfigs r ON r.config = v.number
|
|
WHERE v.type = 'C'
|
|
GO
|
|
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
-- ServerCollector: Starttidspunkt, logiske CPU'er, schedulers, NUMA-noder, fysisk hukommelse og virtualisering.
|
|
-- -------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Variant: SQL Server 2012 og nyere
|
|
-- Kilde: ServerCollector.BuildSql(2012+)
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ServerCollector.cs : ServerCollector.BuildSql(version)
|
|
SELECT
|
|
(SELECT sqlserver_start_time FROM sys.dm_os_sys_info),
|
|
cpu_count,
|
|
(SELECT COUNT(*) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
(SELECT COUNT(DISTINCT parent_node_id) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
physical_memory_kb / 1024,
|
|
virtual_machine_type_desc
|
|
FROM sys.dm_os_sys_info
|
|
GO
|
|
|
|
-- Variant: SQL Server 2008 R2 SP1 og senere 2008 R2-builds
|
|
-- Kilde: ServerCollector.BuildSql(2008 R2 SP1)
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ServerCollector.cs : ServerCollector.BuildSql(version)
|
|
SELECT
|
|
(SELECT sqlserver_start_time FROM sys.dm_os_sys_info),
|
|
cpu_count,
|
|
(SELECT COUNT(*) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
(SELECT COUNT(DISTINCT parent_node_id) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
physical_memory_in_bytes / 1048576,
|
|
virtual_machine_type_desc
|
|
FROM sys.dm_os_sys_info
|
|
GO
|
|
|
|
-- Variant: SQL Server 2008 og 2008 R2 før SP1
|
|
-- Kilde: ServerCollector.BuildSql(2008)
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ServerCollector.cs : ServerCollector.BuildSql(version)
|
|
SELECT
|
|
(SELECT sqlserver_start_time FROM sys.dm_os_sys_info),
|
|
cpu_count,
|
|
(SELECT COUNT(*) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
(SELECT COUNT(DISTINCT parent_node_id) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
physical_memory_in_bytes / 1048576,
|
|
CAST(NULL AS nvarchar(60))
|
|
FROM sys.dm_os_sys_info
|
|
GO
|
|
|
|
-- Variant: SQL Server 2005
|
|
-- Kilde: ServerCollector.BuildSql(2005)
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ServerCollector.cs : ServerCollector.BuildSql(version)
|
|
SELECT
|
|
(SELECT create_date FROM sys.databases WHERE database_id = 2),
|
|
cpu_count,
|
|
(SELECT COUNT(*) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
(SELECT COUNT(DISTINCT parent_node_id) FROM sys.dm_os_schedulers WHERE status = N'VISIBLE ONLINE'),
|
|
physical_memory_in_bytes / 1048576,
|
|
CAST(NULL AS nvarchar(60))
|
|
FROM sys.dm_os_sys_info
|
|
GO
|
|
|
|
-- Variant: SQL Server 2000 (legacy ODBC-sti): starttidspunkt
|
|
-- Kilde: ServerCollector.StartTimeSql(2000)
|
|
-- Kode: src/SQLInsight.Collectors/Db.cs : Db.StartTimeSql(version)
|
|
SELECT (SELECT login_time FROM master.dbo.sysprocesses WHERE spid = 1)
|
|
GO
|
|
|
|
-- Variant: SQL Server 2000 (legacy ODBC-sti): CPU og hukommelse
|
|
-- Kilde: ServerCollector.Sql2000
|
|
-- Kode: src/SQLInsight.Collectors/Instance/ServerCollector.cs : ServerCollector.Sql2000
|
|
EXEC master.dbo.xp_msver
|
|
GO
|