≡ Menu

How Much Swap Space to Add for Oracle Database on Linux

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
Add your comment

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

Comments on this entry are closed.

  • daro October 18, 2013, 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.

  • pathum October 18, 2013, 7:23 am

    thanks for sharing Valuable infomation

  • Rodrigo October 20, 2013, 4:03 pm

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

  • d.b.kid November 4, 2013, 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

  • Rahman Syed May 14, 2016, 10:48 pm

    The article is very informative and you have done an awesome job. I would appreciate if you answer to my question. Thanks in advance.

    I have read about /Swap or swapping mechanism, Increasing the swapping would reduce the performance of the system. In the real world, do companies care about increasing the Physical memory is a good solution than increasing the swap space and have moderate size of RAM.

    Rahman Syed