SQL SERVER – How to take InMemory – OLTP FileGroup Offline?

来源:互联网 时间:1970-01-01

InMemory topics are always interesting and a great learning experience. When I wrote theother post, it was more about how InMemory tables are loaded into memory even if they are not queried. The basics, here is to bring the data for In Memory Tables ahead to memory irrespective of their usage.

After this blog post was published, someone wrote me a mail asking if it is possible to take the InMemory Filegroups offline? And will the table’s data taken offline too? This question was obvious but still needed validation and I was curious to understand why this wouldn’t work in normal circumstances. The script to start working on this post has to startfrom previous post. Please create the database and then before the cleanup step – start to run the below scripts.

At this stage, your query must return some value for the below query:

<span>USE </span><span>IM_OLTP</span><span>;<br /> </span><span>GO<br /> </span><span>SELECT </span><span>CONVERT</span><span>(</span><span>CHAR</span><span>(</span><span>20</span><span>), </span><span>OBJECT_NAME</span><span>(</span><span>OBJECT_ID</span><span>)) </span><span>AS </span><span>Name</span><span>,*<br /> </span><span>FROM </span><span>sys.dm_db_xtp_table_memory_stats<br /> </span><span>WHERE </span><span>OBJECT_ID</span><span>&gt; </span><span>0</span>

For all practical purposes, InMemory tables and filegroups are just like normal files. We should be able to take them offline using the same way we can do other filegroups.

<span>-- Take InMemory FG offline<br /> </span><span>ALTER DATABASE </span><span>IM_OLTP MODIFY </span><span>FILE </span><span>(</span><span>NAME </span><span>= </span><span>'IM_OLTP_mod'</span><span>, </span><span>OFFLINE</span><span>)<br /> </span><span>GO<br /> </span>

This should complete successfully and when we run the above DMV query to find the memory consumers, this must return no rows.

<span>SELECT </span><span>CONVERT</span><span>(</span><span>CHAR</span><span>(</span><span>20</span><span>), </span><span>OBJECT_NAME</span><span>(</span><span>OBJECT_ID</span><span>)) </span><span>AS </span><span>Name</span><span>,*<br /> </span><span>FROM </span><span>sys.dm_db_xtp_table_memory_stats<br /> </span><span>WHERE </span><span>OBJECT_ID</span><span>&gt; </span><span>0</span>

Now that was pretty simple and easy to figure out. I would like to know if you have ever done anything like this in your systems?

Quick Quiz Question:

Now if taking the filegroup offline was easy, what about bringing the filegroup online next?

<span>ALTER DATABASE </span><span>IM_OLTP MODIFY </span><span>FILE </span><span>(</span><span>NAME </span><span>= </span><span>'IM_OLTP_mod'</span><span>, </span><span>ONLINE</span><span>)<br /> </span><span>GO</span>

Simple isn’t it? No. You will encounter an error:

Msg 155, Level 15, State 1, Line 1

‘ONLINE’ is not a recognized CREATE/ALTER DATABASE option.

So the quiz question is, how can we bring the filegroup online in SQL Server 2014 version? What are the steps. Let me know via comments.

Reference: Pinal Dave ( http://blog.sqlauthority.com)



相关阅读:
Top