SSMS not releasing system memory - sql-server

I just started at a new office as a Data Analyst. The job entails upgrading client systems from our dbase platform to our new RDBMS. The actual conversion is handled by some in-house software that is a black box to me but at the end of the conversion my system memory usage is maxed out ~15.3 of 16GB. I was told to just restart my computer but it seems like there must be a better way (hopefully that doesn't involve fixing the software since that is out of scope for me).
I found the question at the link below but running DBCC DROPCLEANBUFFERS doesn't seem to work. Restarting the SQL instance works but that interrupts all the databases on the instance. Is there another way to release the memory?
SQL Server clear memory
We use both ssms2008r2 and smss2012.
Thanks

SQL Server will grab and keep all memory that you let it. If you don't want it to use 15.3 GB of memory, you need to change the setting so it only grabs X GB.
You can do this by right clicking the instance in the object explorer, click on Server Properties, and change the Maximum server memory under the Memory tab. It is generally a good idea to leave at lest 1 - 2 GB for the operating system, and then more if you have anything else running on the server (you should avoid running other stuff on the server, if possible).

SQL by design wants to use as much memory as it can get. If you wish to limit that, you can do so from the server properties and limit it how many GBs its allowed to consume.

DBCC DROPCLEANBUFFERS clears all the clean buffers from the buffer pool. That won't help you.
You need to understand that SSMS isnt eating your memory, the sqlserver service is. SQL server will expand it's memory footprint as much as you will allow it. If you have 32GB and you say it can use 32GB then it will allocate as much as it can.
Here's a great article on DBA stack exchange regarding max server memory: https://dba.stackexchange.com/questions/47431/why-is-sql-server-consuming-more-server-memory

Related

SQL Server Memory Optimization

This is going to be my first attempt at fine tuning our SQL Server 2008R2, and I'd like a starting point based on the following.
When I view the resource monitor, I see (in KB):
Commit: 843,948
Working Set: 718,648
Shareable: 26,276
Private: 692,372
Out of 2 gigs available on our virtual server, 1.6 is getting used up, and I suspect it is due SQL Server, and the memory gets chewed up when I initiate a service that does a bunch of TVP inserts and checks. I already added some GC.collect() in my c# service, however I'm not really seeing much of a change, which leads me back to the SQL Server.
Where would be a good starting point for me to learn more about optimizing based on this information, and some quick pointers?
Thanks.
Here is a quick pointer: buy more memory. 2GB is nothing today.
For the long answer: you need to understand how SQL Server allocates and uses memory. 1.6Gb on a 2Gb box is perfectly normal. See Dynamic Memory Management:
When SQL Server starts, it computes the size of virtual address space
for the buffer pool based on a number of parameters such as amount of
physical memory on the system, number of server threads and various
startup parameters. SQL Server reserves the computed amount of its
process virtual address space for the buffer pool, but it acquires
(commits) only the required amount of physical memory for the current
load.
The instance then continues to acquire memory as needed to support the
workload. As more users connect and run queries, SQL Server acquires
the additional physical memory on demand. A SQL Server instance
continues to acquire physical memory until it either reaches its max
server memory allocation target or Windows indicates there is no
longer an excess of free memory; it frees memory when it has more than
the min server memory setting, and Windows indicates that there is a
shortage of free memory.
In other words, SQL Server will not release the 1.6Gb unless there is memory pressure notification from Windows.
And finally, about your question on where to look for info on optimizations: Waits and Queues is an excellent resource. It is a methodology that allows you to identify the bottlenecks and recommends the appropriate action for all common bottleneck cases.
SQL Server is designed to pre-allocate and "eat up" all the memory you let it use. There really is no way to see any improvement except to reduce the SQL footprint in the configuration.
If it's the default configuration, sql server will analyse usage and then grab as much memory as it can to optimise itself. If other apps then start asking for memory it gives it back.
There are a couple of values you can play with in terms of memory, a minimum which is the amount sql server will keep to itself, and a maximum which it will never grab more than. You can also play around with the number of threads it will run. You'll need some good stats for this. Depends on your usage patterns, and what else needs memory and how well it plays with others. Mess about and you can starve sql server, which is never a brill idea. I've always been a big fan of dedicated machines for dbms for any non trivial use.
As much art as science this, unless you find something horrible in there, slowing down your sql server will give your applications lots of memory to do nothing with because they are waiting for the Db....
More stuff to have a look at.
MSDN - Sql Server Performance and Memory
You need to get performamnce monitoring going and a have a good idea what sort of things are going on during the run. And you want an 'average' run. Peak hits, Out of office hours processing, holidays etc, no use at all.
PS don't forget performance monitoring is a significant hit on the machine.

SQL Server - Does it really release memory when another process needs it?

We have an 8 Core, 16GB RAM server that has SQL Server 2008 running on it. When we perform large queries on millions of rows the RAM usage goes up to 15.7GB and then even file browsing, opening excel etc gets really slow.
So does SQL Server really release memory when another process needs it or am I having another issue? We don't have any other major programs running on this server.
We've set a max memory usage of 14GB for SQL Server.
Thanks all for any enlightenment or trouble shooting ideas.
Yes it does. See SQLOS's memory manager: responding to memory pressure for details how this works. But what exactly means to have 'memory pressure' it depends from machine to machine and from OS version to OS version, see Q & A: Does SQL Server always respond to memory pressure?. If you want to reserve more memory for applications (I'm not even bother to ask why you browse files and use Excel on a machine dedicated to SQL Server....) then you should lower the mas server memory until it leaves enough for your entertainment.
SQL server does NOT release memory. It takes all the memory it can get up to the MaxMemory setting and it stays there.

SQL SERVER 2008 - Memory Leak while storing Millions of records

I need some help very badly.
I'm working on a project where a bulk of data is entered all the time. It's a reporting software.
10 Million records in an average is stored per day and it could keep on increasing as users increase.
As of now, SQL SERVER CONSUMES 5gb of RAM on the task manager. I have an 8GB ram on my server now.
How do other enterprises manage such situations?
SQL Server uses memory efficiently and takes as much as it can. It's also usually clever enough to release memory when needed.
Using 5GB means:
SQL Server is configured to 5GB or SQL Server has simply reserved this memory during normal usage
It's left 3GB because it doesn't need to use it
Nothing is wrong... and I'd probably configure the SQL Server max mem to 6.5GB...
Late addition: Jonathan Kehayias blog entry
SQL Server typically uses as much memory as it can get it's hands on, as it then stores the more frequently accessed data in memory to be more efficient, as disk access is slower then memory access.
So nothing is wrong with it using 5gb of memory.
To be honest, it's leaving 3gb of memory for other applications and the operating system, so there might not be anything wrong with this. (If this is all that server is designed to do.).
To configure the memory limit, do the following:
In SQL Server Enterprise manager, right click on the server name, and go to properties.
Click on the Memory option
Reduce the maximum server memory to what you think is appropriate.
Click ok.
I highly doubt that this is in fact a memory leak. The increase of SQL Server's memory usage is by design, simply because it caches a lot of stuff (queries, procedures).
What you will most likely see is that if the available memory that is still left runs low, SQL server will 'flush' its memory, and you would see in fact that memory will be freed in the end.

SQL Memory usage

I'm managing a co-located winserver08 box running both IIS and SQL 08 express. I just happened to glance at the task manager's performance tab and find the 'mem usage history graph is close to topped out reading 1.8 gig (i have 2 gig physical ram). Processes shows sqlserver is running at 940,000K - by far the largest consumer.
I'm a low volume site - cpu utilization barely registers. Haven't had any stability issues with the server at all. Is this just how SQL treats available mem or should I be digging deeper?
thx
SQL Server manages it's own memory pool. It will release memory back to the OS under memory pressure.
So, yes, this is normal behaviour and nothing to be concerned about.
Note: I should mention an exception to this: If TSQL scripts are using sp_OACreate to create COM objects and not releasing the object with a corresponding sp_OSDestroy (say, for instance an error occurs and the script terminates prematurely), then memory can leak. Use of these stored procedures is not that common (many DBAs won't allow this feature to be turned on, for good reason) I believe this is also the case for CURSORS that are not deallocated.
Unless you have configured this is normal behavior. Read this article for a clear understanding of memory configuration and recommendations.
In your case, I assume you have the default settings and what you see is normal and there is no cause for concern.
Raj
Keep into account SqlExpress probably manages memory in a different way compared to any standard edition (that is, any non-express edition).
I can't provide specific links but from personal experience things change a lot when you move to a proper distribution of SQLServer (speed, memory-manamgement, responsiveness in extreme conditions, etc).
If anybody knows something more please integrate my answer.
SQL Server will use something in the area of 90% of a machine's memory if it isn't capped. This is completely normal as SQL Server is managing memory for itself and will release memory as necessary.
If you are worried about it than you can cap the amount of memory SQL Server can use, by going to the properties of the sqlexpress instance, selecting the memory page and then reducing the maximum server memory.

SQL Server 2k5 memory consumption?

I have a development vm which is running sql server as well as some other apps for my stack, and I found that the other apps are performing awfully. After doing some digging, SQL Server was hogging the memory. After a quick web search I discovered that by default, it will consume as much memory as it can in order to cache data and give it back to the system as other apps request it, but this process often doesn't happen fast enough, apparently my situation is a common problem.
There however is a way to limit the memory SQL Server is allowed to have. My question is, how should I set this limit. Obviously I'm going to need to do some guess and check, but is there an absolute minimum threshhold? Any recommendations are appreciated.
Edit:
I'll note that out developer machines have 2 gigs of memory so I'd like to be able to run the vm on 768 mb or less if possible. This vm will be only used for local dev and testing , so the load will be very minimal. After code has been tested locally it goes to another environment where the SQL server box is dedicated. What I'm really looking for here is recommendations on minimums
Extracted fromt he SQL Server documentation:
Maximum server memory (in MB)
Specifies the maximum amount of memory
SQL Server can allocate when it starts
and while it runs. This configuration
option can be set to a specific value
if you know there are multiple
applications running at the same time
as SQL Server and you want to
guarantee that these applications have
sufficient memory to run. If these
other applications, such as Web or
e-mail servers, request memory only as
needed, then do not set the option,
because SQL Server will release memory
to them as needed. However,
applications often use whatever memory
is available when they start and do
not request more if needed. If an
application that behaves in this
manner runs on the same computer at
the same time as SQL Server, set the
option to a value that guarantees that
the memory required by the application
is not allocated by SQL Server.
The recommendation on minimum is: No such thing. The more memory the better. The SQL Sever needs as much memory as it can get or it will trash your IO.
Stop the SQL Server. Run your other applications and take note to the amount of memory they need. Subtract that from your total available RAM, and use that number for the MAX memory setting in the SQL Server.
Since this is a development environment, I agree with Greg, just use trial and error. It's not that crucial to get it perfectly right.
But if you do a lot of work in the VM, why not give it at least half of the 2GB?
so id like to be able to run the vm on
768 mb or less if possible.
That will depend on your data and the size of your database. But I usually like to give SQL server at least a GB
It really depends on what else is going on on the machine. Get things running under a typical load and have a look at Task Manager to see what you need for everything else. Try that number to start with.
For production machines, of course, it is best to give control of the machine to Sql Server (Processors -> Boost Sql Server Priority) and let it have all the RAM it wants.
Since you are using VMs, maybe you could create a dedicated one just for Sql Server and run everything else on a different VM.

Resources