8 days ago
Our production PostgreSQL service shows a large, persistent RAM increase immediately after its scheduled PITR backup.
Image: ghcr.io/railwayapp-templates/postgres-ssl:18
PITR: Enabled
On August 13 at 08:02 UTC, pgBackRest ran a differential backup:
- Backup size: 5.3 GB
- Backup completed successfully in ~80 seconds
- Railway memory jumped from ~0.9 GB to ~6.0 GB
- Memory subsequently remained around 6.54 GB
- CPU remained almost idle
The container’s cgroup memory breakdown shows this is almost entirely filesystem cache:
anon: 77,197,312 bytes
file: 6,236,610,560 bytes
shmem: 171,614,208 bytes
kernel: 55,054,336 bytes
This appears to be pgBackRest reading the database into the Linux page cache. It does not look like a PostgreSQL process memory leak, but Railway’s metrics count the cache as service RAM.
Is there a supported workaround that preserves PITR without restarting PostgreSQL after every backup?
We would prefer to keep PITR enabled, but retaining roughly the entire backup size as billable RAM after each daily backup could become expensive as the database grows.
1 Replies
Status changed to Awaiting Railway Response Railway • 8 days ago
8 days ago
You've diagnosed this exactly right. That memory is Linux page cache from pgBackRest reading your data directory during the backup, not a Postgres leak. To be equally straight on the numbers: billed memory is the container's cgroup memory.current plus swap, sampled every 30 seconds, with nothing subtracted, so that cache does count until something evicts it.
One reassurance: it can't hurt the service. It's clean, reclaimable memory, and the kernel evicts it before anything else if your workload ever needs the RAM, so there's no OOM or performance risk from it sitting there.
The supported way to keep it from accumulating is a service memory limit. Your real usage is around 1 GB, so a limit of 4 GB gives plenty of headroom while creating just enough pressure for the kernel to reclaim the backup cache on its own instead of letting it sit at 6 GB until the next restart. Reclaim happens well before any OOM risk at that sizing. That keeps PITR exactly as it is, with no restarts and nothing to run after each backup.
Separately, I'm raising with the team that owns the Postgres image whether it should release that cache automatically at the end of each backup, since you're not the first to hit this. I'll follow up if that lands.
Railway Team
Status changed to Awaiting User Response Railway • 8 days ago
a day ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • about 23 hours ago