现象:

SQL Server 2019中,某个数据库在SQL Server Management Studio(SSMS)中的状态显示为“正常,已自动关闭”。

解释:

如此显示,是由于该数据库的AUTO_ CLOSE选项被设为True。

在微软的官方文档中,对于这个选项是这样介绍的:

When AUTO_CLOSE is set ON, this option can cause performance degradation on frequently accessed databases because of the increased overhead of opening and closing the database after each connection. AUTO_CLOSE also flushes the procedure cache after each connection.

If a database is accessed frequently, set the AUTO_CLOSE option to OFF for the database.

译文如下:

当AUTO_ CLOSE启用时,由于在每次连接时增加了打开和关闭数据库的开销,该选项可能导致频繁访问的数据库性能降低。在每次连接后,AUTO_ CLOSE也会清理过程缓存。

如果某个数据库经常被访问,则应设置该数据库的AUTO_ CLOSE选项为关闭。

解决方法:

打开该数据库的属性,在左侧选择“选项”。然后在右侧找到“自动”分组,将“自动关闭”设置为False。

参考内容:

Set the AUTO_CLOSE Database Option to OFF - SQL Server | Microsoft LearnCheck whether the AUTO_ CLOSE option is OFF. The AUTO_ CLOSE option has implications for performance in SQL Server.icon-default.png?t=O83Ahttps://learn.microsoft.com/en-us/sql/relational-databases/policy-based-management/set-the-auto-close-database-option-to-off?view=sql-server-ver15

Logo

一站式 AI 云服务平台

更多推荐