How Much Swap Space to Add for Oracle Database on Linux

by Ramesh Natarajan on October 17, 2013

If you are running Oracle database on your environment, and having some performance issues because of memory, you may have to look at the swap space configured on your system.

For Oracle 11g database, the following is the recommendation from Oracle in terms of how much space space you should add.

  • If your RAM size is less than or equal to 2 GB, your swap size should be 1.5 times of the RAM. For example, if your RAM size is 2 GB, you should create swap space of 3GB
  • If your RAM size is between 2 GB and 16 GB, your swap size should be the same size of the RAM. For example, if your RAM size is 4 GB, you should create swap space of 4GB
  • If your RAM size is more than 16 GB, your swap size should be 16 GB. For example, if your RAM size is 32 GB, it is enough if you create a swap space of 16GB

There are also lot of other parameters come into play when you are configuring your database for performance. If your database needs large SGA size for performance reasons, you may want to consider using HugePages. By default the SGA page size is chunked into 4k. When you use HugePages, you the SGA page size is chuncked into a minimum of 2MB. You have to keep this in mind, when you are configuring your database.

You can view the current HugePagesize as shown below.

$ grep Huge /proc/meminfo
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     4096 kB

This Oracle article will give you an introduction to hugepages, which you may want to consider, when you are using large memory.

On Linux, execute the free command, to identify the current RAM size and SWAP size. By default free command shows output in kb. Since we gave -m option, it is displaying the output in MB. As shown below, this system has 3 GB of RAM and 2 GB of swap.

$ free -m
             total       used       free     shared    buffers     cached
Mem:          3034       2907        126          0        107       1103
-/+ buffers/cache:       1696       1338
Swap:         2047         85       1962

You can also get the total RAM size, and swap size of your system from the /proc/meminfo file as shown below. This displays the output in kilo bytes.

$ egrep 'MemTotal|SwapTotal' /proc/meminfo
MemTotal:      3107636 kB
SwapTotal:     2096472 kB

You can add swap space to your system using any one of the two methods that explained in this How to add swap space article.

The following example will add 1 GB of swap file to your Linux system.

dd if=/dev/zero of=/root/myswapfile bs=1M count=1024

chmod 600 /root/myswapfile

mkswap /root/myswapfile

swapon /root/myswapfile

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 4 comments… read them below or add one }

1 daro October 18, 2013 at 3:00 am

We only allocate 8GB of swap on production Oracle servers.
Server should never swap more than megabytes not to affect performance of your server. You should seriously review you config and spec if server is heavily swapping.

2 pathum October 18, 2013 at 7:23 am

thanks for sharing Valuable infomation

3 Rodrigo October 20, 2013 at 4:03 pm

Oracle 11g is not a database but a database management system …

4 d.b.kid November 4, 2013 at 9:06 am

Oracle has same requirements for Oracle 12c, also. Actually it’s non mandatory requirement, but they recommend this policy. They has mandatory requirement only for RAM – minimum: 1GB, recommended: 2 GB of RAM or more

Leave a Comment

Previous post:

Next post: