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

Rentrop picture Rentrop · Jan 26, 2017 · Viewed 9.2k times · Source

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

Answer

Ilya Dyoshin picture Ilya Dyoshin · Feb 7, 2017

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