sql安装程序初始化_SQL Server安装程序–即时文件初始化(IFI)

sql安装程序初始化

If SQL Server needs to allocate space, first it fills the space it needs with zeros. Examples of when it needs to allocate space are creating/restoring a database, growing/allocating data and log files, and finally the troublesome auto growth operation. However, most of these slowdowns/long running actions can be improved by enabling instant file initialization. I say most because the one case where this is required is on log file growth. However, even when Instant file initialization has been enabled the log file will be zeroed out before the space is usable for SQL Server.

如果SQL Server需要分配空间,则首先用零填充它所需的空间。 它何时需要分配空间的示例包括创建/还原数据库,增长/分配数据和日志文件,最后是麻烦的自动增长操作。 但是,通过启用即时文件初始化,可以改善大多数此类减慢/长时间运行的操作。 我之所以这么说是因为需要这样做的一种情况是日志文件的增长。 但是,即使启用了即时文件初始化,日志文件也会在该空间可用于SQL Server之前清零。

Instant file initialization skips the zero-writing step and allows SQL Server to use the allocated space immediately. The main benefit is that during restore or file growth functions it will be considerably faster and reduce downtime in case of an emergency.

即时文件初始化跳过了零写入步骤,并允许SQL Server立即使用分配的空间。 主要优点是在恢复或文件增长功能期间,它将大大加快速度并减少紧急情况下的停机时间。

As mentioned above, in many cases this a good idea, however, this is not the case for all scenarios. This is because when initializing a file on the OS level, the operating system will try to format those blocks to be zeros. This is like a hard format which is done when first inserting disks. The reason the OS does this is because it prevents people from reading data that was deleted by the user but still existed on the disk. When enabling IFI, this is basically switching the SQL Server disk allocations to lazy format, which will zero out the disk only when it needs to write to the disk. I will add that this can be a security issue but it is still a common and best practice to enable this. Make sure to discuss internally before making this choice for your organization as it could be a problem depending on what you store.

如上所述,在许多情况下,这是一个好主意,但并非在所有情况下都如此。 这是因为在操作系统级别上初始化文件时,操作系统将尝试将这些块格式化为零。 这就像在第一次插入磁盘时完成的硬格式一样。 操作系统这样做的原因是因为它阻止人们读取用户删除但仍存在于磁盘上的数据。 启用IFI时,这基本上是将SQL Server磁盘分配切换为惰性格式,仅当需要将其写入磁盘时才会将磁盘清零。 我将补充一点,这可能是一个安全问题,但启用它仍然是一种常见的最佳实践。 在为您的组织做出选择之前,请确保内部进行讨论,因为根据您存储的内容,这可能是一个问题。

However, I will also add that most of the time the potential security concern is eliminated because most enterprises are using SAN technology to store their databases. In the article about instant file initialization, Microsoft mentions these concerns and mitigates it by stating “If the database files are hosted on a storage area network, it is also possible that the storage area network always presents new pages as pre-initialized, and having the operating system re-initialize the pages might be unnecessary overhead.” I invite you all to read the article on the MSDN located here.

但是,我还要补充一点,因为大多数企业都在使用SAN技术来存储其数据库,所以大多数时候都消除了潜在的安全隐患。 在有关即时文件初始化的文章中,Microsoft提到了这些问题,并通过声明“如果数据库文件托管在存储区域网络中,则存储区域网络总是会在预初始化后呈现新页面,并且操作系统重新初始化页面可能是不必要的开销。” 我邀请大家阅读此处位于MSDN上的文章。

Even if your business is not using a SAN, it is very common to turn Instant File Initialization on. Many shops consider the increased performance benefit to far outweigh the small security risk, but you must weigh the cost and benefits within your own environment.

即使您的企业未使用SAN,也很常见的是启用即时文件初始化。 许多商店认为提高的性能收益远远超过了较小的安全风险,但是您必须权衡自己环境中的成本和收益。

This all sounds great, right? So how do you go about enabling this on your SQL machine. Well, before we touch on this, I will add, that this is only necessary if you are not running your sql server service account as local system or as a member of the administrator’s group. By default, Microsoft has the permissions granted to these groups to already have Instant file initialization on. When reviewing why, I found Microsoft documentation on the perform volume maintenance tasks policy that states “This policy setting determines which users can perform volume or disk management tasks, such as defragmenting an existing volume, creating or removing volumes, and running the Disk Cleanup tool.” Obviously, this makes sense since those are core functions of any OS.

听起来不错,对吗? 因此,如何在SQL机器上启用它。 好吧,在我们进行讨论之前,我要补充一点,这仅在您没有以本地系统或管理员组成员身份运行SQL Server服务帐户时才需要。 默认情况下,Microsoft授予这些组的权限,以启用即时文件初始化。 在查看原因时,我发现有关执行卷维护任务策略的Microsoft文档指出:“此策略设置确定哪些用户可以执行卷或磁盘管理任务,例如对现有卷进行碎片整理,创建或删除卷以及运行磁盘清理工具。 。” 显然,这是有道理的,因为这些是任何OS的核心功能。

You can doublecheck this by running the following SQL query.

您可以通过运行以下SQL查询来仔细检查。

SELECT  servicename as Service_Display_Name,
	   service_account as Service_Account,
        instant_file_initialization_enabled as Instant_File_Initialization_Enabled
FROM    sys.dm_server_services
WHERE   servicename LIKE 'SQL Server (%'

If your query returns that you do not have this enabled, you can run through the following steps:

如果查询返回您未启用此功能,则可以执行以下步骤:

As a side note, always run changes through a change management process or on a development environment prior.

附带说明一下,始终在变更管理流程或开发环境中运行变更。

先决条件 (Prerequisite)

  • Instant file initialization is only available if the SQL Server (MSSQLSERVER) service account has been granted SE_MANAGE_VOLUME_NAME.

    只有在已授予SQL Server(MSSQLSERVER)服务帐户SE_MANAGE_VOLUME_NAME的情况下,即时文件初始化才可用。

更改SQL Server服务帐户 (Changing the SQL Server Service account)

  • Start menu, point to 开始”菜单上,指向“ All Programs, point to Microsoft SQL Server 2012, point to所有程序” ,再指向“ Microsoft SQL Server 2012”,再指向“  Configuration Tools, and then click 配置工具” ,然后单击“ SQL Server Configuration Manager. SQL Server配置管理器”
  • SQL Server Services. SQL Server服务”
  • Properties. 属性”
  • In the SQL Server Properties dialog box, click the Log On tab, and select a Log on as account type.
  • 在“ SQL Server属性”对话框中,单击“ 登录”选项卡,然后选择“作为帐户登录”类型。
  • OK. 确定
    • A message box asks whether you want to restart the SQL Server service.

      出现一个消息框,询问您是否要重新启动SQL Server服务。
  • Yes, and then close SQL Server Configuration Manager. 是” ,然后关闭“ SQL Server配置管理器”。

启用即时文件初始化 (Enabling Instant File Initialization )

To grant an account the Perform volume maintenance tasks permission: This option is housed in the local security policies under > local policies > users rights assignments. You will the add your user to the perform volume maintenances tasks and select apply.

授予帐户“执行卷维护任务”权限:此选项位于>“本地策略”>“用户权限分配”下的本地安全策略中。 您将把您的用户添加到执行卷维护任务中,然后选择“应用”。

Similar steps can be followed in group policy, however, depending on your structure for your group policy it can get a bit messy.

组策略中可以遵循类似的步骤,但是,根据组策略的结构,它可能会有些混乱。

  • Group Policy Management 组策略管理
  • Group Policy Objects 组策略对象”
  • Create a new Policy with your domain’s naming convention.

    使用您域的命名约定创建新策略。
  • Once created, edit the policy by right clicking and selecting edit

    创建策略后,通过右键单击并选择“编辑”来编辑策略
  • Navigate to Computer Configuration -> Polices -> Windows Settings -> Security Settings -> Local Policies -> User Rights Assignments

    导航到计算机配置->策略-> Windows设置->安全设置->本地策略->用户权限分配
  • Perform Volume Maintenance Tasks 执行卷维护任务

sql安装程序初始化_SQL Server安装程序–即时文件初始化(IFI)_第1张图片
    • In the case of multiple SQL servers with different accounts, create a group for them prior, if you have not already done so.

      如果多个SQL Server具有不同的帐户,请先为它们创建一个组(如果尚未创建)。
  • Once added, apply the policy to the appropriate OU

    添加后,将策略应用于相应的OU

使用Adventureworks测试还原时间 (Testing restore times with Adventureworks )

To test some of the benefits we are going to try to compare restoring the adventureworks2017 database with and without Instant file initialization. A disclaimer, with such a small database (97MB .bak file) you will likely see a more drastic result with larger databases.

为了测试一些好处,我们将尝试比较在使用和不使用即时文件初始化的情况下还原Adventureworks2017数据库的情况。 免责声明:使用如此小的数据库(97MB .bak文件),对于较大的数据库,您可能会看到更加激烈的结果。

To start, we will restore the Adventureworks2017 database with instant file initialization enabled, following this we created a local user account, creatively named SQLServer with it disabled (shown below)

首先,我们将还原启用了即时文件初始化的Adventureworks2017数据库,此后,我们创建了一个本地用户帐户,该帐户创造性地命名为SQLServer,并且已将其禁用(如下所示)

sql安装程序初始化_SQL Server安装程序–即时文件初始化(IFI)_第2张图片

sql安装程序初始化_SQL Server安装程序–即时文件初始化(IFI)_第3张图片

Using the filtering feature for the SQL Server logs, we can get the speed of the restores.

使用SQL Server日志的筛选功能,我们可以获得还原的速度。

As you can see the second test, we saw a 25% difference in speed for restoring a database, which can be job saving in a DR scenario.

如您所见,在第二项测试中,我们发现还原数据库的速度相差25%,这在灾难恢复场景中可以节省工作。

常见问题 ( FAQs )

When should I enable instant file initialization?

什么时候应该启用即时文件初始化?

Almost always, there is almost no security risk but there are tremendous benefits.

几乎总是没有安全风险,但有很多好处。

How can I tell Instant file initialization is enabled?

我如何知道启用即时文件初始化?

This can be seen by running the query below.

通过运行下面的查询可以看到这一点。

How to enable instant file initialization?

如何启用即时文件初始化?

Well, you might not need to but a policy can be pushed locally or through a group policy.

好吧,您可能不需要,但是可以在本地或通过组策略推送策略。

翻译自: https://www.sqlshack.com/sql-server-setup-instant-file-initialization-ifi/

sql安装程序初始化

你可能感兴趣的:(数据库,java,mysql,python,大数据)