Microsoft SQL Server เป็นอัจฉริยะมากในแง่ของ Memory Management แต่บางครั้ง Memory Pressure Alerts และ Database Engines ต้องการ Memory มากขึ้น นำไปสู่ Errors
บทนำ
โพสต์นี้อภิปรายวิธีแก้ไข Exceptional Scenario หนึ่งที่คุณอาจประสบเนื่องจาก Memory Pressure บน SQL Server® 2019 (Enterprise Edition) ที่เกิดจาก Memory-optimized Tables (In-memory Online Transaction Processing (OLTP)) ขั้นตอนเดียวกันใช้ได้กับ SQL Server 2014 และใหม่กว่า
คุณอาจเห็น Error Messages ต่อไปนี้บนหน้าจอของคุณ:
Message: MSSQL on Windows: Stolen Server Memory is too high Source: XXXXX\MSSQLSERVER Path: Not Present Alert description: SQL instance "MSSQLSERVER" Stolen Server Memory on computer "XXXXXXX.XXX.com" is too high. Message: SQL Server Alert System: 'Severity 17' occurred on \\XXXXXXX DESCRIPTION: There is insufficient system memory in resource pool 'internal' to run this query. Message: Disallowing page allocations for database 'InMemoryDB' due to insufficient memory in the resource pool 'default'. See 'https://go.microsoft.com/fwlink/?LinkId=510837' for more information. Message: XTP failed page allocation due to memory pressure: FAIL_PAGE_ALLOCATION 32 Solution
ทำตามขั้นตอนต่อไปนี้เพื่อ Troubleshoot และ Resolve ปัญหานี้:
Step One
ขั้นตอนแรกคือตรวจสอบ Memory Consumption ใน SQL Buffer Pool
ตามที่คุณเห็นจากภาพก่อนหน้า Database ที่เกี่ยวข้อง InMemoryDB Consume เพียง 0.017% ของ Buffer Pool
Step Two
จากนั้นคุณตรวจสอบ OS Memory Clerks โดยใช้ T-SQL Command ต่อไปนี้:
select * from sys.dm_os_memory_clerks order by pages_kb desc
Results แสดงว่า Total ของ Top Consumers ประมาณ 80% ของ Total Maximum Server Memory
ขนาดของ Memory-optimized Tables ก็น้อยกว่า 2 GB ซึ่งคุณเห็นในภาพก่อนหน้าสำหรับ Name DB_ID_6 ดังนั้นในทาง Ideal ไม่ควรมี Memory Pressure บน Server
Step Three
หลังจาก Review Out of Memory (OOM) Links ที่กล่าวถึงใน Error Log https://go.microsoft.com/fwlink/?LinkId=510837 คุณต้อง Bind Database ที่มี Memory-optimized Tables ไปยัง Resource Pool การ Bind นี้เป็น Best Practice สำหรับ Databases ที่มี Memory-optimized Tables ทำตามขั้นตอนเพื่อสร้าง Resource Pool ใน Resource Governor และ Bind Database
Best Practices แนะนำว่า คุณควรปกป้อง SQL Server จากการถูก Consume Resources โดย Memory-optimized Tables หนึ่งหรือมากกว่า และป้องกัน Memory Users อื่นๆ จากการ Consume Memory ที่ Memory-optimized Tables ต้องการ ดังนั้น คุณควรสร้าง Resource Pool แยกต่างหากเพื่อจัดการ Memory Consumption สำหรับ Database ที่มี Memory-optimized Tables
เก็บ Points ต่อไปนี้ไว้ในใจเมื่อ Add Database ไป Resource Pool:
- คุณสามารถ Bind Database ได้เพียงหนึ่ง Resource Pool
- คุณสามารถ Bind Multiple Databases ไป Pool เดียวกันได้
- SQL Server เปิดใช้งาน Binding Database ที่ไม่มี Memory-optimized Tables ไป Resource Pool แต่ไม่มี Effect
- คุณสามารถสร้าง Memory-optimized Tables ใน Database หลังจาก Bind ไป Resource Pool แล้ว
Steps to Bind to a Resource Pool
-
Create Resource Pool พร้อม Memory Allocations:
USE [master] GO CREATE RESOURCE POOL [Admin_Pool] WITH(min_cpu_percent=0, max_cpu_percent=100, min_memory_percent=15, max_memory_percent=15, cap_cpu_percent=100, AFFINITY SCHEDULER = AUTO, min_iops_per_volume=0, max_iops_per_volume=0) GOหมายเหตุ: เพื่อหลีกเลี่ยง Out-of-memory Conditions ค่าของ min_memory_percent และ max_memory_percent ควรเหมือนกัน
ในกรณีนี้ Memory-optimized Tables เล็กมาก มี 15% ของ Total Server Memory Allocated ให้ Resource Pool อย่าลืมใช้ Links ใน References เพื่อคำนวณ Percent ของ Memory ใน Environment ของคุณ
-
Verify Resource Pool และ Bind Database ไปยังมัน:
EXEC sp_xtp_bind_db_resource_pool 'InMemoryDB', 'Admin_Pool' GO -
Verify Bind ใน sys.databases:
SELECT d.database_id, d.name, d.resource_pool_id FROM sys.databases d GO
-
Restart Database เพื่อทำให้ Binding Active:
ALTER DATABASE DB_Name SET OFFLINE GO ALTER DATABASE DB_Name SET ONLINE GO
หมายเหตุ: หาก Database เป็น Always On ให้ทำ Steps บน Both Nodes และแทน Step 4 (Restart Databases) ให้ทำ Database Failover ไป Secondary Instance
สรุป
ในกรณีนี้ Alerts ทั้งหมดที่เกี่ยวข้องกับ Memory Pressure หยุดลงหลังจาก Add Databases ที่มี Memory-optimized Tables ไป Resource Pool ผม Monitor SQL Server Error Logs เป็นสองสัปดาห์สำหรับ Issue นี้โดยเฉพาะ และไม่มี Traces ของ Memory Pressure ใดๆ ขั้นตอนเหล่านี้ช่วย Fix Memory Pressure บน Database Engine Level ด้วย Minimal Downtime
ใช้แท็บ Feedback เพื่อแสดงความคิดเห็นหรือถามคำถาม คุณยังสามารถเริ่มสนทนากับเราได้