Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres why is swap-usage growing? How to reduce it? - AWS RDS

Having a postgres DB on AWS-RDS the Swap Usage in constantly rising.

Why is it rising? I tried rebooting but it does not sink. AWS writes that high swap usage is "indicative of performance issues"

I am writing data to this DB. CPU and Memory do look healthy: enter image description here

To be precise i have a
db.t2.micro-Instance and at the moment ~30/100 GB Data in 5 Tables - General Purpose SSD. With the default postgresql.conf.

The swap-graph looks as follows:

enter image description here

Swap Usage warning:

enter image description here

like image 389
Rentrop Avatar asked Jan 26 '17 15:01

Rentrop


People also ask

Why is my swap usage so high?

A higher percentage of swap use is normal when provisioned modules make heavy use of the disk. High swap usage may be a sign that the system is experiencing memory pressure. However, the BIG-IP system may experience high swap usage under normal operating conditions, especially in later versions.

How can I improve my RDS performance?

DB instance RAM recommendations An Amazon RDS performance best practice is to allocate enough RAM so that your working set resides almost completely in memory. The working set is the data and indexes that are frequently in use on your instance. The more you use the DB instance, the more the working set will grow.

How do I reduce swap utilization?

To clear the swap memory on your system, you simply need to cycle off the swap. This moves all data from swap memory back into RAM. It also means that you need to be sure you have the RAM to support this operation. An easy way to do this is to run 'free -m' to see what is being used in swap and in RAM.

Why is my Amazon RDS DB Instance using swap memory when I have sufficient memory?

RDS DB instances require pages in the RAM only when the pages are currently accessed, such as when running queries. Other pages that are brought into the RAM by previously run queries are flushed to swap space if they weren't used recently.


2 Answers

Well It seems that your queries are using a memory volume over your available. So you should look at your queries execution plan and find out largest loads. That queries exceeds the memory available for postgresql. Usually over-much joining (i.e. bad database structure, which would be better denonarmalized if applicable), or lots of nested queries, or queries with IN clauses - those are typical suspects. I guess amazon delivered as much as possible for postgresql.conf and those default values are quite good for this tiny machine.

But once again unless your swap size is not exceeding your available memory and your are on a SSD - there would be not that much harm of it

like image 104
Ilya Dyoshin Avatar answered Sep 18 '22 08:09

Ilya Dyoshin


check the

select * from pg_stat_activity;

and see if which process taking long and how many processes sleeping, try to change your RDS DBparameter according to your need.

like image 43
Biswajit Mohanty Avatar answered Sep 18 '22 08:09

Biswajit Mohanty