Skip to content

AWS RDS PostgreSQL: baseline swap jump after enabling `max_slot_wal_keep_size` (and OS upgrade)

0

Hi everyone,

I’m seeing an unexpected increase in baseline swap usage on AWS RDS for PostgreSQL after two changes that happened in the same maintenance window (Jul 15-th):

  • Set a finite value for max_slot_wal_keep_size in the DB parameter group (to harden replication safety) - after setting it back to -1 swap usage is growing again
  • Rebooted the instances to apply the change
  • Also applied an RDS OS upgrade on the same instances during this window

What I observe:

  • Within hours, SwapUsage (CloudWatch) grew from a few MB to several hundred MB and stays elevated
  • This happened in both testing and staging environments
  • No obvious change in workload around the time of the change

Replication:

  • Replication slots are in use

Questions for the community:

  • Could setting a finite max_slot_wal_keep_size indirectly affect memory usage (e.g., via WAL sender/archiver behavior) in a way that increases swap?
  • Has anyone observed sustained swap increases on recent RDS PostgreSQL OS images following maintenance?

I am happy to provide more details if helpful (exact RDS engine version, instance class, CloudWatch metric screenshots and pg_stat_activity snapshots).

Attached screenshots are from db.m7g.large Postgres 16.9 in eu-west-1 AWS region, but same problem is affecting other instance types and other Postgres versions.

Thanks in advance for any insights !

Mem and SWAP usage CPU utilization

asked a year ago431 views

1 Answer
-1

The increased swap usage you're observing after setting a finite value for max_slot_wal_keep_size and the OS upgrade could be related to how PostgreSQL manages replication slots and Write-Ahead Log (WAL) retention.

When you set a finite value for max_slot_wal_keep_size, PostgreSQL changes how it manages WAL files for replication slots. This parameter limits how much disk space can be consumed by WAL retention for replication slots. While this helps prevent unbounded disk usage growth from inactive replication slots, it can affect memory usage patterns.

Here's what might be happening:

  1. WAL management changes: With a finite max_slot_wal_keep_size, PostgreSQL may be changing its WAL processing behavior, potentially affecting memory allocation patterns for WAL senders and related processes.

  2. Replication slot monitoring: The system might be allocating additional memory to track WAL usage against the new limit, especially if you have multiple replication slots.

  3. OS upgrade impact: The RDS OS upgrade that occurred simultaneously could have introduced changes to memory management, swap policies, or default configurations that contribute to the increased swap usage.

  4. Background processes: The change might have affected how background processes like WAL writers and checkpointers operate, potentially leading to different memory usage patterns.

The fact that swap usage grows again after setting max_slot_wal_keep_size back to -1 suggests that the parameter is indeed related to the behavior you're seeing. With -1, PostgreSQL doesn't limit WAL retention for replication slots, which can lead to different memory allocation patterns.

To further troubleshoot:

  1. Monitor PostgreSQL wait events, particularly those related to WAL operations like WALWriteLock.

  2. Check if there are any changes in checkpoint behavior or frequency, as these can affect memory and I/O patterns.

  3. Examine if there are any inactive or lagging replication slots that might be affecting WAL retention.

  4. Consider enabling Performance Insights for more detailed analysis of database load and memory usage patterns.

If the swap usage continues to be a concern, you might want to consider adjusting your instance size or memory configuration to accommodate the new behavior, or contact AWS Support for a more in-depth investigation of the OS-level changes that might have occurred during the upgrade.
Sources
WALWriteLock wait elevated without any obvious cause | AWS re:Post
DMS between two RDS instances, grown OldestReplicationSlotLag | AWS re:Post
Understanding transaction visibility in PostgreSQL clusters with read replicas | AWS Database Blog

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.