SSIS Server Maintenance Job ends up using all of server memory - sql-server

For some reason the SSIS Server Maintenance Job ends up having the SQL Server instance use all available server memory after a few runs (it runs every midnight). When that happens, my SSIS packages no longer have memory to run in and start swapping on disk which leads to unacceptable execution times or at worst a total hang.
So far I've been resetting the SQL Server service through Configuration Manager every morning, but that's not a viable long term solution. I have not set maximum memory limit for the SQL Server instance. Would that help? If not, what can I do?
Server information: Azure VM, 32 GB ram, no other purpose for the server than running SSIS.

You should always set a maximum memory limit for SQL Server instances.
A simple rule of thumb is to leave 4GB or 10% of total memory free, whichever is larger, and tweak as necessary.
If your SQL Server instance is running as a VM, then you also need to set a memory reservation at the host for your VM. Otherwise, the host's 'balloon memory manager' might kick in and steal memory back from your instance.
Ref:
Server memory configuration options
Understanding Memory Resource Management in VMware

Related

SQL Server is not releasing memory after Daily Load

We have a SQL Server 2012 Enterprise Edition, 128GB of RAM, Windows 2008R2. The SQL Server job runs every day at 3 AM and takes 5 hrs to load data into the database. During this process, SQL Server utilizes 123GB (max memory allocated).
After the job completes, SQL Server is not releasing the RAM.
Queried memory utilization where buffer pool shows 97GB. Users don't access database during this time. I restarted SQL Server services to bring RAM down. I didn't find a correct answer related to this issue. Why is it not releasing the RAM? How can we bring RAM utilization down?
SQL Server Job -> SSIS package -> Import data from Mysql to SQL Server database
Thanks
This is by design once SQL Server uses memory, it keeps hold of it and does not release it back to OS.
Your Task Manager may show all/nearly all memory used by SQL Server but if you want to see how much memory SQL Server is actually using you can use the following query.
SELECT (physical_memory_in_use_kb/1024) AS Memory_usedby_Sqlserver_MB
FROM sys.dm_os_process_memory;
By design, SQL Server holds on to the RAM that is has allocated. Much of the RAM is used for the buffer pool. The buffer pool is a cache that holds database pages in memory for fast retrieval.
If SQL Server were to release some memory, and someone were to run a query that requests it right afterwards, the query would have to wait for expensive physical I/O to produce the data. Therefore, SQL Server tries to hold as much memory as possible (and as configured) for as long as possible.
The RAM settings here specify the min server memory and the max server memory. Careful setting of the max memory setting allows room for other processes to run. The article quotes a complicated formula for determining how much room to leave:
From the total OS memory, reserve 1GB-4GB to the OS itself.
Then subtract the equivalent of potential SQL Server memory allocations
outside the max server memory control, which is comprised of stack
size 1 * calculated max worker threads 2 + -g startup parameter 3 (or
256MB by default if -g is not set). What remains should be the
max_server_memory setting for a single instance setup.
In our servers, we usually just wing it and set the max memory option to several GB below the total physical memory. This leaves plenty of room for the OS and other applications.
If SQL Server memory is over the min server memory, and the OS is under memory pressure, SQL Server can release memory until it is at the min server memory setting.
Reference: Memory Management Architecture Guide.
One of the primary design goals of all database software is to
minimize disk I/O because disk reads and writes are among the most
resource-intensive operations. SQL Server builds a buffer pool in
memory to hold pages read from the database. Much of the code in SQL
Server is dedicated to minimizing the number of physical reads and
writes between the disk and the buffer pool. SQL Server tries to reach
a balance between two goals:
Keep the buffer pool from becoming so big that the entire system is low on memory.
Minimize physical I/O to the database files by maximizing the size of the buffer pool.
When SQL Server is using memory dynamically, it queries the system
periodically to determine the amount of free memory. Maintaining this
free memory prevents the operating system (OS) from paging. If less
memory is free, SQL Server releases memory to the OS. If more memory
is free, SQL Server may allocate more memory. SQL Server adds memory
only when its workload requires more memory; a server at rest does not
increase the size of its virtual address space.
...
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.
As other applications are started on a computer running an instance of
SQL Server, they consume memory and the amount of free physical memory
drops below the SQL Server target. The instance of SQL Server adjusts
its memory consumption. If another application is stopped and more
memory becomes available, the instance of SQL Server increases the
size of its memory allocation. SQL Server can free and acquire several
megabytes of memory each second, allowing it to quickly adjust to
memory allocation changes.
If, for some reason:
You absolutely MUST have that memory back
You know you do not need it for a while
You are willing to pay a penalty for virtual memory allocation and physical I/O to retrieve data from disk the next time you need that memory
Then you can temporarily reconfigure the database max server memory setting to a lower value. This can be done through the SSMS user interface, or you can use an sp_configure 'max server memory' followed by reconfigure to make the changes programatically.
Full disclosure: I did not try it myself.
You should not try it on your production environment before testing it somewhere else.
This is from a DBA answer:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'max server memory', 4096;
GO
RECONFIGURE;
GO
4096 should be replaced by the value that you find acceptable as the minimum.
Should be followed by a similar command to increase the memory back to your original maximum.

how to release memory of SQL Server?

I have a server that saves 1000 record every minute, I wrote a trigger that does a series of jobs for every row and I used a lot of table and other variables in it. Now my SQL Server memory usage increases very fast and I can't manage it.
I set min server memory and max server memory but it can't help me, when I set max memory server my SQL Server performance decreased and save process interrupted.
I used these resources but these can't help me:
Great SQL Server Debates: Lock Pages in Memory
How to: Set a Fixed Amount of Memory (SQL Server Management)
I have to reset SQL Server Service every 4 hour but this is not a correct way.
How to release memory of SQL Server?

SQL Server DB Engine Memory Leakage

We have a Windows Form Application and the back-end of the application is SQL Server Express 2005/2008. Our application can be installed on Windows XP SP3/ Windows Vista/ Windows 7.
We have observed huge memory leakage in SQL Server Express.
Normally, there are two process running even if the application is not used by the user:
A polling process to check the availability of files. (If files are not available then, only one query is fired to check some configuration setting)
A Scheduling process. (This process fires a query every minute to check for any scheduled task)
We have observed that the memory usage of the SQL Server (sqlsrvr.exe) keeps on increasing. In around an hour, the memory usage reaches upto 1GB and it never comes down.
We have also noticed that, if the interval of the polling process is increased, then the memory usage increases gradually but, it does increase.
The higher memory usage by SQL server downgrades the machine performance and the performance of all other applications running on the machine.
Please provide suggestions to control the memory usage of SQL server in this case.
PFB the details:
Software causing issue :SQL Server 2005/2008 Express editions (named instance)
Operating Systems on which issue can be simulated : Windows XP SP3/ Windows Vista/ Windows 7
Regards,
Abhineet
SQL Server is designed to take all the memory on the system and use it for its internal cache. You should never run anything else on the same machine as SQL Server. This is not a leak, is the intended and desired behavior. By design. See Memory Manager Architecture
As a special case SQL Server Express edition limits its internal buffer pool size to 1Gb. The buffer pool is not the only memory consumed by SQL Server though. You can further limit the SQL Server buffer pool size by specifying a value for max server memory.

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.

Limited memory usage of sql server 2008 express?

I want to install sql server 2008 express on my laptop that has 1 GB memory, but my database contains lots of binary data that I don't want spending all my RAM. I would much rather sacrifice sql performance (make it page) in favor of other applications.
Is it possible to limit the memory footprint of sql server?
look here and here
essentially sp_configure 'max server memory' I think
I've only got SQL Server 2005 Express, not 2008, but from SQL Server Management Studio Express, if I right-click on the root node in the tree (the server node) and select Properties, there's a "Memory" page with both minimum and maximum amounts of memory available to be set.
From the docs for these options:
Minimum server memory (in MB)
Specifies that SQL Server should start
with at least the minimum amount of
allocated memory and not release
memory below this value. Set this
value based on the size and activity
of your instance of SQL Server. Always
set the option to a reasonable value
to ensure that the operating system
does not request too much memory from
SQL Server and inhibit Windows
performance.
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.
I'd be surprised if these options weren't in 2008, but you could always just install it and try.
You can do it w/ osql:
http://kb.hs-lab.com/content/7/113/en/how-to-limit-ram-usage-for-sql-2005-express-database.html
osql -E -S YOURSERVERNAME\PRINTLOGGER
sp_configure 'show advanced options',1
RECONFIGURE WITH OVERRIDE
GO
then
sp_configure 'max server memory',70?
RECONFIGURE WITH OVERRIDE
GO
You might also try giving cpu priority to your favored applications and letting SQL manage memory dynamically. It will release memory as needed by other apps, regardless of priority.
Hopefully you're not trying to run visual studio on that machine. It won't be much fun.

Resources