Skip to content

Commit 7e85b2e

Browse files
committed
Add BufferPoolExtension to scripts
1 parent af6edbb commit 7e85b2e

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Scripts/BufferPoolExtension.sql

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Author:Ryan Adams
3+
Original link: http://www.ryanjadams.com/2017/05/implementing-buffer-pool-extension
4+
*/
5+
6+
--Review current BPE configuration
7+
SELECT [path], state_description, current_size_in_kb,
8+
CAST(current_size_in_kb/1048576.0 AS DECIMAL(10,2)) AS [Size (GB)]
9+
FROM sys.dm_os_buffer_pool_extension_configuration;
10+
11+
--Reduce SQL Server Max memory to restrict the BP and force the use of BPE
12+
EXEC sys.sp_configure 'show advanced options', '1' RECONFIGURE WITH OVERRIDE;
13+
GO
14+
EXEC sys.sp_configure 'max server memory (MB)', '2000';
15+
GO
16+
RECONFIGURE WITH OVERRIDE;
17+
GO
18+
EXEC sys.sp_configure 'show advanced options', '0' RECONFIGURE WITH OVERRIDE;
19+
GO
20+
/*********** WE HAVE TO RESTART SQL SERVER FOR BPE TO SEE THE RAM CHANGE ***************/
21+
22+
--Enable BPE
23+
--Go look at the file size on disk right after you run this
24+
ALTER SERVER CONFIGURATION
25+
SET BUFFER POOL EXTENSION ON (FILENAME = 'C:\Temp\BP_Extension.BPE', SIZE = 2 GB);
26+
27+
--Now that it is enabled we'll inspect the configuration again
28+
SELECT [path], state_description, current_size_in_kb,
29+
CAST(current_size_in_kb/1048576.0 AS DECIMAL(10,2)) AS [Size (GB)]
30+
FROM sys.dm_os_buffer_pool_extension_configuration;
31+
32+
--Try to read enough data to fill BP and start using BPE
33+
USE AdventureworksDW2016CTP3;
34+
GO
35+
SELECT * FROM dbo.FactResellerSalesXL_PageCompressed;
36+
--If the above didn't do the trick then query this table as well
37+
--SELECT * FROM dbo.FactResellerSalesXL_CCI;
38+
39+
--Let's see what went to BPE. If there are no results then go query more data.
40+
SELECT DB_NAME(database_id) AS [Database Name], COUNT(page_id) AS [Page Count],
41+
CAST(COUNT(*)/128.0 AS DECIMAL(10, 2)) AS [Buffer size(MB)],
42+
AVG(read_microsec) AS [Avg Read Time (microseconds)]
43+
FROM sys.dm_os_buffer_descriptors
44+
WHERE database_id <> 32767
45+
AND is_in_bpool_extension = 1
46+
GROUP BY DB_NAME(database_id)
47+
ORDER BY [Buffer size(MB)] DESC;
48+
49+
--Turn BPE off. Go look in c:\temp to see what happens to the physical data file
50+
ALTER SERVER CONFIGURATION
51+
SET BUFFER POOL EXTENSION OFF;
52+
53+
--Put Max Server Memory back where it was
54+
EXEC sys.sp_configure 'show advanced options', '1' RECONFIGURE WITH OVERRIDE;
55+
GO
56+
EXEC sys.sp_configure 'max server memory (MB)', '3500';
57+
GO
58+
RECONFIGURE WITH OVERRIDE;
59+
GO
60+
EXEC sys.sp_configure 'show advanced options', '0' RECONFIGURE WITH OVERRIDE;
61+
GO

0 commit comments

Comments
 (0)