Increase the swap space EC2 Instance


Sep 2018

Increase the swap space EC2 Instance


If you are on a EC2 micro instance and constantly running out of memory or need additional swap space for your application requirements such as Oracle DB, Oracle UCM or SOA, you can follow the below Instructions to increase the swap space (default is zero)




  1. Login to your EC2 Instance and sudo to root
  2. Create a swap file on this device, run the following command for a 8GB swapfile

    /bin/dd if=/dev/zero of=/var/mgdswap bs=1M count=8192

    where /var/mgdswap = Name of the Swapfile
    count = Size of the file

  3. Make and flag it as Swap Space using the below command

    /sbin/mkswap /var/mgdswap

  4. Set permissions on the file for group and user restrictions using the below command

    chown root:root /var/mgdswap

    chmod 600 /var/mgdswap

  5. Enable the swap using the below command

    /sbin/swapon /var/mgdswap

  6. Now the most important step, to enable it by default after reboot, add the below line to /etc/fstab

/var/mgdswap swap swap defaults 0 0




Post Your Thoughts

Your email address will not be published. Required fields are marked *