Bobcares

How to fix Amazon RDS DB instance using swap

PDF Header PDF Footer

Is your Amazon RDS DB instance using swap memory when you already have sufficient memory? Well, the Support Engineers at Bobcares have a solution for this snag.

If you are running an Amazon RDS DB where your DB instance is using more swap memory even though you have enough memory, it is time to call in the experts. The Support Team at Bobcares resolved this problem for one of our customers recently and is happy to share the solution here.

Why is Amazon RDS DB instance using swap memory?

Amazon Elastic Compute Cloud instances rely on swap memory when the system winds up requiring more memory than allocated. So when you find your Amazon RDS DB instance using swap memory even though you have allocated sufficient memory can be confusing. Fortunately, our Support Team is well-versed in coming up with solutions for issues like these.

The Amazon RDS DB instances need pages in the RAM only in situations where the pages are accessed. For instance, while executing queries.

The process involves bringing in other pages into the RAM by previously executed queries. This flushes swap space in case the pages are not used recently. In other words, the OS rends to swap older pages rather than holding on to pages. This ensures that plenty of free RAM is available for upcoming queries.

Furthermore, swap memory is not cleared frequently in Linux as it requires extra overhead to reallocated the cleared swap. So if swap space is used by the RDS DB instance, the SwapUsage metrics will not return to zero.

Additionally, swap memory is also utilized when you use HugePages on RDS for PostgreSQL or HugePages supported by Amazon RDS Oracle.

How to fix Amazon RDS DB instance using swap memory?

In order to resolve this particular issue, we will first take a look at the DB performance metrics based on the application load. This involves taking a look at SwapUsage and FreeableMemory Amazon CloudWatch metrics. Moreover, it also helps you to get a grasp of the overall memory usage pattern of the RDS DB instance.

Verify if there is a decrease in the FreeableMemory metric while there is an increase in the SwapUsage metric at the same time.

This is a clear indication of pressure on the RDS DB instance’s memory. In case the FreeableMemory remains low consistently, change the RDS DB instance size to one with more memory.

You can monitor SwapUsage by turning on Enhanced Monitoring. It collects statistics at the host level while CloudWatch collects data every sixty seconds from the hypervisor level.

Moreover, you can turn on Performance Insights to identify the SQL as well as wait events responsible for excessive memory or swap on the RDS DB instance.

Amazon RDS MySQL using Swap memory

If you notice freeable memory is low, execute SHOW FULL PROCESSLIST. This will review the threads running on the database.

The process ID displayed by Enhanced Monitoring will not match the one from the output of SHOW FULL PROCESSLIST.

In order to see the correct process ID, change the DB parameter group associated with the database to enable Performance_Schema.

Moreover, since it is static, you need to reboot the RDS DB instance. Once the memory has reached the required usage, follow these steps:

  1. First, sort the process IDS in the Enhanced Monitoring page to identify the ones consuming maximum CPU.
  2. Then, execute the following query as master user:
    select * from performance_schema.threads where THREAD_OS_ID in (ID shown in the Enhanced Monitoring window)\G

    For instance: execute the following query if the maximum memory is consumed by Thread_OS_Id 10373 and 1432:

    select * from performance_schema.threads where THREAD_OS_ID in (10373, 1432)\G
  3. Then, access the PROCESSLIST_ID of the output from the executed in the previous step. This will match the process ID from SHOW FULL PROCESSLIST.

Amazon RDS PostgreSQL using Swap memory

In this scenario, our Support Engineers first identify the process responsible for consuming a high amount of memory. The process ID from the Enhanced Monitoring process list is mapped to the exact query by running:

select * from pg_stat_activity where pid=(the PID of your process);

Then, we will configure the queries to consume less memory.

Amazon RDS SQL Server using Swap memory

Enhanced Monitoring comes in handy to identify the thread ID that is consuming more memory. The thread ID also goes by the name, Kernal process ID by SQL Servers.

You can access this information by running the following query:

select * from sys.sysprocesses where kpid = '<Value of Thread ID from Enhanced Monitoring>' ;

Run the following command for instance if you get hold of the server process ID as 68:

dbcc inputbuffer(68)

Amazon RDS Oracle using Swap memory

Here, we will use the OS process ID from Enhanced Monitoring, to identify which process is using the most memory. Then, we will execute this query to attain the process address:

select ADDR from v$process where SPID=OS_PID;

In turn, the process address identifies the session within the database with the following query:

select sid,serial#,username, status from v$session where PADDR='<ADDR from above query>';

[Need some help with Server Management? We are here to lend a hand 24/7.]

Conclusion

To conclude, we learned how to resolve the issue when an Amazon RDS DB instance uses swap memory even if there is sufficient memory available. The talented Support Team at Bobcares showed us the root cause behind the issue and how to resolve it by tracking Freeablememory and SwapUsage.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF