[系列文章] 淺談如何標準化作業規範 - Setting max server memory in SQL Server

如何把例行的作業變成自動化規範來避免人為遺漏?

繼上一篇[系列文章] 淺談如何標準化作業規範 - Use 64k block for SQL Server

例行公事:setting max server memory in sql server

我們檢查了 64k block size 之後,接下來就要設定一下 max server memory 了

為什麼要設定 max server memory 呢 ??? 大家都知道 SQL Server 是個愛吃記憶體的怪獸

但是為什麼會變成怪獸呢 ??? 因為常常有人會忽略去控制它的食量而導致它變成了怪獸

德瑞克老師有一篇很棒的文章告訴我們記憶體的重要性

SQL 效能調教:規劃記憶體(RAM Capacity)到比資料表、資料庫還要大的容量

因此我們要依照我們手邊有的資源以及經驗來判斷 SQL Server 倒底要給多少記憶體

首先定義幾個變數,然後盡可能地撰寫一個通用的 function 供我們呼叫使用

function CheckConfigurations()
{
	$command.CommandText = $query
	$result = $command.ExecuteReader()
	$table = new-object "System.Data.DataTable"
	$table.Load($result)

	If ($table[0].value -eq $value)
		{
			$message = "OK."
			$message | Out-File -Append $reportPath"\"$reportFile

			$format = @{Expression={$_.value};Label=$queryname;width=$width}
			$table | format-table $format | Out-File -Append $reportPath"\"$reportFile
			$endmark | Out-File -Append $reportPath"\"$reportFile
		}
	Else
		{
			$message = "Warning! Please check " + $queryname + "."
			$message | Out-File -Append $reportPath"\"$reportFile

			$format = @{Expression={$_.value};Label=$queryname;width=$width}
			$table | format-table $format | Out-File -Append $reportPath"\"$reportFile
			$endmark | Out-File -Append $reportPath"\"$reportFile
		}
}



$query = "SELECT value FROM sys.configurations WHERE name = 'max server memory (MB)'"
$value = 32768
$queryname = "max server memory (MB)"
CheckConfigurations

在這裡,我使用 PS 去查詢了 sys.configurations 返回我目前的設定值

然後檢查一下是否與我期望的 max memory 相符,並產出一個像這樣的 report


(待續...)