尝试SQL Server 2014 OLTP memory-optimized表遇到的问题

本文涉及的产品
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云数据库 RDS SQL Server,基础系列 2核4GB
简介:

SQL Server 2014引入了内存数据库,这是个非常好的功能。数据可以直接在内存中,这样可以直接对内存进行操作,性能有很大的提高。


今天想到一个问题,如果表增长的大了,而数据库内存不够会出现什么样的情况。因为微软的MSDNS上是这样写的额:

A computer with enough memory to hold the data in memory-optimized tables. Memory-optimized data must not use more than 80% of the maximum server memory.


也就是不要超过整个INSTANCE内存的80%,但是数据库的增长有时候是无法预料的啊。下面开始我的测试:


--Create database with memory-optimizeddata filegroup

CREATE DATABASE Hekaton_Demo

ON

PRIMARY(NAME = [hekaton_demo_data],

FILENAME = 'C:\DATA\hekaton_demo_data.mdf',size=500MB)

, FILEGROUP [hekaton_demo_fg] CONTAINSMEMORY_OPTIMIZED_DATA(

NAME = [hekaton_demo_dir],

FILENAME = 'C:\DATA\hekaton_demo_dir')

LOG ON (name = [hekaton_demo_log], Filename='C:\DATA\hekaton_demo_log.ldf',size=500MB)

COLLATE Latin1_General_100_BIN2;

GO


USE Hekaton_Demo;

GO


CREATE TABLE Destination1
(
--See the section on bucket_count for more details on setting the bucket count.
col1 INT NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1000000),
col2 varchar(1000) NOT NULL,
col3 varchar(1000) NOT NULL
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
GO


尝试把BUCKET_COUNT再乘以100倍创建的时候就报错了:

Msg 701, Level 17, State137, Line 37

There is insufficientsystem memory in resource pool 'default' to run this query.


--尝试插入大量数据:


DECLARE @INT INT

SET @INT = 1

WHILE @INT < 1000000

BEGIN

INSERT INTO Destination1 VALUES(@INT,REPLICATE('A',1000),REPLICATE('A',1000))

SET @INT = @INT +1

END


结果执行了一段时间之后数据库连接直接断开了,SSMS看到的错误信息:


Timeout expired.  The timeout period elapsed prior tocompletion of the operation or the server is not responding. (.Net SqlClientData Provider)


数据库错误日志:

Msg 701, Level 17, State137, Line 37

There is insufficientsystem memory in resource pool 'default' to run this query.


重启一次失败:

13-06-30 18:23:55.23Logon       Error: 17188, Severity: 16,State: 1.

2013-06-30 18:23:55.23Logon       SQL Server cannot accept newconnections, because it is shutting down. The connection has been closed.[CLIENT: <local machine>]

再次重启:


2013-06-30 18:30:40.98 spid23s     Error: 41316, Severity: 23, State: 4.

2013-06-30 18:30:40.98 spid23s     Restore operation failed for database'Hekaton_Demo'.


2013-06-30 18:13:18.08 spid38s     Error: 802, Severity: 17, State: 0.

2013-06-30 18:13:18.08 spid38s     There is insufficient memory available inthe buffer pool.


还是失败,没办法直接删除数据库重启成功。


不知道SQL Server是如何在创建表的时候计算内存的,对于变量如何计算呢?因为值根本是不确定的。如果开始创建表不报错在后面的时候出现这种问题那就比性能问题更严重了。


再去找找文档看看微软是如何解释的。


本文转自 lzf328 51CTO博客,原文链接:
http://blog.51cto.com/lzf328/1236078
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
相关文章
|
SQL 关系型数据库 RDS
How to Troubleshoot High CPU in RDS for SQL Server
Sometimes we come with high CPU usage of RDS for SQL Server instance. Here's some common steps to troubleshoot this issue.
2332 0
|
SQL 关系型数据库 测试技术
SQL Server FullText解决Like字句性能问题
# 场景引入 这天老鸟火急火燎的冲到菜鸟座位:“还记得你在云栖社区发表的一篇名为‘SQL Server利用HashKey计算列解决宽字段查询的性能问题’的文章吗?被人踢馆啦,人家觉得你这个限制条件太苛刻,只能解决完全等于的问题条件下的性能问题,没有太大的现实意义。” 菜鸟烧脑的调动大脑的每一个细胞:“哦,你说的是这篇文章啊?”。 [SQL Server利用HashKey计算列解决宽字段查
3788 0
|
SQL 关系型数据库 数据库
PostgreSQL一条SQL引发系统out of memory
错误描述 (1) Postgres执行的原SQL: select COALESCE(m1.place_id, m2.place_id, m3.place_id) as place_id, concat_ws('``', m1.
2013 0
|
SQL Go 数据库
SQL Server使用sys.master_files计算tempdb大小不正确
原文:SQL Server使用sys.master_files计算tempdb大小不正确 一直习惯使用sys.master_files来统计数据库的大小以及使用情况,但是发现sys.master_files不能准确统计tempdb的数据库大小信息。
1184 0