"There is insufficient system memory in resource pool 'default' to run this query" error with MEMORY_OPTIMIZED tables
0
votes
0
answers
1717
views
I use Memory-Optimized Table in my SQL Server. However the error "There is insufficient system memory in resource pool 'default' to run this query" occures after several drop/create/insert operations with MEMORY_OPTIMIZED tables. For example I have created the memory_optimized table and I have loaded some data to the table. After that I have dropped the table, create the table the insert of the same data may be failed with the error "insufficient system memory".
Why may the error occured? Are there any ways how to avoid it?
The steps for reproducing the problem:
Run ms sql server in docker via command:
sudo docker run --memory=3g -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Ab123456" -p 1434:1434 --name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2022-latest
Create test database:
CREATE DATABASE my_db;
ALTER DATABASE my_db
ADD FILEGROUP my_db CONTAINS MEMORY_OPTIMIZED_DATA;
ALTER DATABASE my_db
ADD FILE (
NAME=my_db_my_db,
FILENAME='/tmp/my_db_my_db'
)
TO FILEGROUP my_db;
ALTER DATABASE my_db
SET RECOVERY FULL;
BACKUP DATABASE my_db TO DISK = 'NUL';
Generate some data for testing:
CREATE TABLE test_data (
id int NOT NULL identity(1,1), field varchar(max) NOT NULL
)
WITH (DATA_COMPRESSION = PAGE);
declare @i int;
set @i =1;
while @i<=1000000 begin
set @i=@i+1;
INSERT INTO test_data (field)
VALUES ('asfd');
end;
Create memory_optimized tables:
CREATE TABLE my_memory_table (
id int NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1500000), field varchar(max) NOT NULL
)
WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);
INSERT INTO my_memory_table (id,field)
select top 1000000 id, field from test_data;
The next queries should be repeated several times before the error occures (in our case after 2 or 3 repeates):
DROP TABLE my_memory_table;
CREATE TABLE my_memory_table (
id int NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1500000), field varchar(max) NOT NULL
)
WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);
INSERT INTO my_memory_table (id,field)
select top 1000000 id, field from test_data;
Asked by Iga21207
(1 rep)
Oct 3, 2022, 01:39 PM
Last activity: Oct 3, 2022, 01:49 PM
Last activity: Oct 3, 2022, 01:49 PM