自动关闭配置

Microsoft.SQLServer.Windows.Monitor.Database.AutoCloseConfiguration (UnitMonitor)

监视 Windows 上的数据库的“自动关闭”设置。注意: 默认情况下,此监视器为禁用状态。请根据需要使用替代进行启用。

Knowledge Base article:

摘要

此监视器检查此数据库的“自动关闭”设置。因为此监视器是整体标准要求的一部分,如果该设置不符合指定的标准,将生成警报。

AUTO_CLOSE 选项允许将数据库文件作为常规文件进行管理,因此,该选项对于桌面数据库很有用。它们可以移动、复制以制作备份,或者甚至通过电子邮件发送给其他用户。但是,在数据库设置为 AUTOCLOSE = ON 时,启动数据库自动关闭的操作将清除 SQL Server 实例的计划缓存。清除计划缓存将导致对所有后续执行计划进行重新编译,并可能导致查询性能暂时性地突然降低

数据库镜像要求将 AUTO_CLOSE 设置为 OFF。

只有在确保应用程序使用模式将在相对较长的期间中保持数据库关闭的情况下,自动关闭才有意义。某些单用户应用和某些多租户数据库宿主情况可能会从 AUTO_CLOSE ON 中获益。对于所有其他用法,通常这样做并不好,除非真正理解应用程序行为和使用模式

  • 设计/实现说明 - 来自 BOL

  • 如果数据库未启动,则 Microsoft SQL Server 通过直接访问数据库而不是通过从元数据检索值而检索到的属性将返回 NULL。即,数据库的 AUTO_CLOSE 设置为 ON,或者数据库已脱机。

配置

当“自动关闭”设置为 ON 时,数据库将在最后一个用户退出后完全关闭,它占用的资源也将释放。

AUTO_CLOSE {ON | OFF}

原因

如果“自动关闭”选项与所需的设置不匹配,将生成一个警告警报。在初始状态下,监视器配置为在此设置为 "ON" 时发出警报。

解决方法

可以通过以下任一方法解决此问题:

或者,如果不对此数据库考虑此监视器:

可替代参数

名称

说明

默认值

警报优先级

定义警报优先级。

正常

警报严重性

定义警报严重性。

警告

已启用

启用或禁用工作流。

预期值

数据库配置设置的预期值。要查看适用值集,请参阅此监视器的知识库文章的“配置”部分。

生成警报

定义工作流是否生成警报。

间隔(秒)

运行工作流的重复间隔时间(秒)。

43200

同步时间

使用 24 小时格式指定的同步时间。可以忽略。

 

超时(秒)

指定工作流在关闭之前允许运行的时间,并标记为失败。

300

数据库连接超时(秒)

如果在指定期间无法访问数据库,工作流将失败并注册一个事件。

15

Element properties:

TargetMicrosoft.SQLServer.Windows.Database
Parent MonitorMicrosoft.SQLServer.Windows.Rollup.Database.AutomaticConfiguration
CategoryConfigurationHealth
EnabledFalse
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.Windows.MonitorType.Database.DBConfigurationStatus
RemotableTrue
AccessibilityPublic
Alert Message
Windows 上的 MSSQL: 自动关闭配置错误
计算机“{2}”上 SQL 实例“{1}”中的数据库“{0}”的“自动关闭”设置未根据最佳实践进行设置。
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.Windows.Monitor.Database.AutoCloseConfiguration" Accessibility="Public" Enabled="false" Target="SqlDiscW!Microsoft.SQLServer.Windows.Database" ParentMonitorID="Microsoft.SQLServer.Windows.Rollup.Database.AutomaticConfiguration" Remotable="true" Priority="Normal" TypeID="Microsoft.SQLServer.Windows.MonitorType.Database.DBConfigurationStatus" ConfirmDelivery="false">
<Category>ConfigurationHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.Windows.Monitor.Database.AutoCloseConfiguration.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.Database"]/DatabaseName$</AlertParameter1>
<AlertParameter2>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</AlertParameter2>
<AlertParameter3>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="ConfigurationValueOK" MonitorTypeStateID="ConfigurationValueOK" HealthState="Success"/>
<OperationalState ID="ConfigurationValueNotOK" MonitorTypeStateID="ConfigurationValueNotOK" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<MachineName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</MachineName>
<NetbiosComputerName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/NetbiosComputerName$</NetbiosComputerName>
<InstanceName>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</InstanceName>
<DatabaseName>$Target/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.Database"]/DatabaseName$</DatabaseName>
<ConfigName>AutoClose</ConfigName>
<ExpectedValue>OFF</ExpectedValue>
<ConnectionString>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/ConnectionString$</ConnectionString>
<InstanceVersion>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Version$</InstanceVersion>
<InstanceEdition>$Target/Host/Property[Type="SqlCoreLib!Microsoft.SQLServer.Core.DBEngine"]/Edition$</InstanceEdition>
<MonitoringType>$Target/Host/Property[Type="SqlDiscW!Microsoft.SQLServer.Windows.DBEngine"]/MonitoringType$</MonitoringType>
<SqlTimeoutSeconds>15</SqlTimeoutSeconds>
<TimeoutSeconds>300</TimeoutSeconds>
<IntervalSeconds>43200</IntervalSeconds>
<SyncTime/>
</Configuration>
</UnitMonitor>