Increase Swap Space Linux for Oracle Installation
While installing Oracle database for one of DEV environments we encountered a error due to small swap space available in machine. As this was used for Development only and not required to be production grade we have made a quick hack to fix the swap space issue without recreating the VM again. So before we dive into the quick hack let’s first know what is swap space and why its required.
A very crisp excerpt is swapping is necessary for two important reasons.
- When the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately.
- A significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.
Now to increase the swap space without recreating the VM can be done by below steps:
- Login as root and check what is the current swap space available and how much needs to be added more using below command.
swapon -s
- From above output you can see the size is approx 3GB but we needed approx 8GB swap space for Oracle 12C enterprise edition installation. So here we have increased 5GB more to the existing 3GB swap. While referring this example use your required value for your system.
- We had maximum free space in /home partition so we have used 5GB extraswap space from here. Choose yours according to your environment. Free space can be checked via below command.
df -kh
- To create a new swap space we have to reserve the same amount of free space using the dd or data dump command. Use below command to reserve as much as space you want to be added to existing swap space. Here in this example we had 5GB requirement so adding a 5GB extra swap file.
dd if=/dev/zero of=/home/oracle/swapspace bs=1M count=5096
Note: Here 5096*1MB is taken, calculate yours and add accordingly.
- So now we are ready with the file /home/oracle/swapspace to use it as secondary swap space. To make the file kernel consumable we need to use mkswap command like below:
mkswap /home/oracle/swapspace
- Now to turn the swapspace file ON we have to run swapon filename like below:
swapon /home/oracle/swapspace
- In the above example output from swapon -s you can see now that the new swap file is now added to the existing swap space. So now new total swap space is 3GB(existing)+5GB(New)=8GB which sufficient for our oracle enterprise edition installation. Though this is a quick hack to increase swap space linux machines but effective.
To Make this change Permanent:
- Edit the fstab file and add a new entry like below
vi /etc/fstab
- Search for existing swap settings and add the below mentioned line next to it and save the file.
/home/oracle/swapspace none swap sw 0 0
To Revert the changes done:
If you wish to revert the changes done to system then follow below steps:
- Run swapoff command to switch off the swapfile use.
swapoff /home/oracle/swapspace
- Run swapon -s to confirm the file is no more listed in swap space files.
- Remove the /home/oracle/swapspace file from disk.
- Revert the /etc/fstab change done.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.