Azure IaaS VM - 使用 D:\ Drive for tempdb - NTFS 格式化 64k

Nic*_*len 8 sql-server azure-vm

这是我今天早些时候正在解决的一个问题,并最终找到答案。不介意更好的东西,但想将它提供给同样需要的人。

首先,在 Azure VM 上,您可以免费获得一个 D:\ 驱动器,即 SSD。需要注意的是,当 VM 重新启动时,它通常会被破坏。MS 高写入量的最佳做法是将此驱动器用于 tempdb。他们没有讨论的是它没有被格式化为 64kb。隐藏的 pagefile.sys 驻留在此处,因此如果您尝试重新格式化(它会失败),则需要考虑到这一点。

从这里:https : //cloudblogs.microsoft.com/sqlserver/2014/09/25/using-ssds-in-azure-vms-to-store-sql-server-tempdb-and-buffer-pool-extensions/

您需要将他们的启动 powershell 脚本更改为更类似于下面的内容,我首先将页面文件完全删除,然后格式化为 64k,按照通常的脚本创建文件,然后在开始之前将 pagefile.sys 放回原处启动服务。

$SQLService=”SQL Server (MSSQLSERVER)”
$SQLAgentService=”SQL Server Agent (MSSQLSERVER)”
$tempfolder=”D:\SQLTEMP”
if (!(test-path -path $tempfolder)) {
    (Get-WmiObject -Class Win32_PageFileSetting).Delete() 
    Format-Volume -DriveLetter D -FileSystem NTFS -AllocationUnitSize 65536 -NewFileSystemLabel "Temporary Storage"  -Confirm:$false
    New-Item -ItemType directory -Path $tempfolder
    Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = 'D:\pagefile.sys';} 
}
Start-Service $SQLService
Start-Service $SQLAgentService
Run Code Online (Sandbox Code Playgroud)

有没有人有更好的东西或在这个过程中看到任何漏洞?

为了给其他人更多的自动化/帮助,我还编写了上面的脚本以及创建它的触发器,并在启动后使用下面的 30 秒运行它。这基本上允许某人自动执行我引用的 cloudblogs 文章中的步骤。

#1 - Set Services to manual startup so that windows scheduler will start after tempdb adjusted
Set-Service -Name MSSQLSERVER -StartupType Manual
Set-Service -Name SQLSERVERAGENT -StartupType Manual
IF (Get-Service MsDtsServer130 -ErrorAction SilentlyContinue)
{
Set-Service -Name MsDtsServer130 -StartupType Manual
}

<#2 - using below powershell script to create the startup script#>
$script=
'
$SQLService="SQL Server (MSSQLSERVER)"
$SQLAgentService="SQL Server Agent (MSSQLSERVER)"
$tempfolder="D:\SQLTEMP"
if (!(test-path -path $tempfolder)) {
    (Get-WmiObject -Class Win32_PageFileSetting).Delete() 
    Format-Volume -DriveLetter D -FileSystem NTFS -AllocationUnitSize 65536 -NewFileSystemLabel "Temporary Storage"  -Confirm:$false
    New-Item -ItemType directory -Path $tempfolder
    Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = "D:\pagefile.sys";} 
}
Start-Service $SQLService
Start-Service $SQLAgentService
IF (Get-Service MsDtsServer130 -ErrorAction SilentlyContinue)
{
Start-Service -Name MsDtsServer130
}
'

Out-File -FilePath C:\SQL-startup.ps1 -InputObject $script -NoClobber


<#3 - using below script to create a scheduled task to call a powershell script that creates a folder on the d drive.#>
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $trigger -FilePath C:\SQL-startup.ps1 -Name CreateSqlFolderOnDSsd
Run Code Online (Sandbox Code Playgroud)

**编辑,上面假设 SQL 2016 和至少 powershell 5(虽然我不知道特定的依赖关系,至少应该在 v4 上工作)。

Dav*_*oft 6

有没有人有更好的东西或在这个过程中看到任何漏洞?

至于漏洞,博客文章包含几个,但您的脚本似乎堵塞了它们。

至于更好的东西,本地 SSD 暂存驱动器上的 TempDB 现在可用于 Azure VM 上的 SQL Server,以及用于数据和日志的单独存储池。以下是 Azure 门户中存储配置窗格的屏幕截图:

在此处输入图片说明

VM 驱动器将被格式化如下:

PS C:\> Get-Volume  | Format-List AllocationUnitSize, FileSystemLabel


AllocationUnitSize : 4096
FileSystemLabel    : Temporary Storage

AllocationUnitSize : 65536
FileSystemLabel    : SQLVMLOG

AllocationUnitSize : 65536
FileSystemLabel    : SQLVMDATA1

AllocationUnitSize : 0
FileSystemLabel    :

AllocationUnitSize : 0
FileSystemLabel    :

AllocationUnitSize : 4096
FileSystemLabel    : System Reserved

AllocationUnitSize : 4096
FileSystemLabel    : Windows
Run Code Online (Sandbox Code Playgroud)

推荐这里使用tempdb的一个64KB分配单元的大小仅可用于当tempdb数据库在远程存储,而不是本地NVMe闪存盘上,并且在任何情况下都不应该有较大的性能影响。