本次实践的主要内容是使用动态内存改进负载。同样,分两部分(十七、十八),大家慢慢看吧。
我们的管理员小张注意到生产环境中的销售应用响应速度变得缓慢,于是他调查了 SQL Server 并发现该服务耗尽了所有可用内存。小张决定用 Hyper-V 与 SQL Server 2012 的动态内存功能让服务器获得尽可能多所需内存。于是他开始了如下的操作。
1、登录到 Hyper-V 服务器 HyperV03,打开 Hyper-V 管理器,选择 Guest01。
2、右键点击并选择关闭。
3、服务器关闭后,右键点击并选择设置,在硬件选项下选择内存。
4、设置下列内存配置,并点击确定。
动态内存 启用
最小内存 512MB
最大内存 1024MB
内存缓冲区 20%
5、选择 Guest01,右键点击并选择启动。
6、选择 Guest01,右键点击并选择连接。
7、以 administrator 登录,密码为 lxh!@#123。
8、从 Codeplex 网站下载并解压缩 Adventure Works 2012 数据库范例:
http://msftdbprodsamples.codeplex.com/releases/view/93587
9、将下载的数据库文件复制到 C:\Program Files\Microsoft SQL Server\
MSSQL11.MSSQLSERVER\MSSQL\DATA。
10、启动 SQL Server Management Studio 并点击连接。
11、选择数据库,右键点击并选择附加。
12、点击添加。
13、打开 C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER
\MSSQL\DATA 并点击确定。
14、点击确定以便附加 AdventureWorks2012 数据库。
15、在对象浏览器中展开数据库选项,选择 AdventureWorks2012 数据库,右键点击并选择新建查询。
16、在查询窗口中复制并粘贴下列命令:
--create the table
create table bigtable (
id integer not null identity(1,1), --8 bytes
pad char(192) default '' not null, --192 bytes
PRIMARY KEY (id) --? bytes
);
go
--fill with data
create procedure bootstrap_database
as
begin
declare @cur integer = 0,
@block integer = 1000,
@table_max integer = 55 * 100000, --approx 1 GB every 5,500,000 rows
@sql nvarchar(max) = 'insert into bigtable (pad) values '
while @cur < @block
begin
set @sql = @sql + N'(''qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrttttttttttyyyyyyyyy''),'
set @cur = @cur + 1
end
--trim trailing ,
set @sql = substring(@sql, 0, len(@sql))
set @cur = 1
declare @handle integer;
exec sp_prepare @handle output, N'', @sql
while IDENT_CURRENT('bigtable') < @table_max
begin
exec sp_execute @handle
set @cur = @cur + @block
end
exec sp_unprepare @handle
end
go
exec bootstrap_database
17、点击执行 �C 该操作可能需要几分钟才能完成。
18、脚本运行完成后,在对象浏览器中右键点击 Guest01 (SQL SERVER ……) 并选择属性。
19、请记录分配给 SQL Server 实例的内存。
20、点击确定。
未完待续,敬请期待……