Deploy Postgres + Flanger
Postgres 18 that lowers high memory usage by dropping unused page cache
postgres
Just deployed
/var/lib/postgresql/data
Deploy and Host Postgres + Flanger with Railway
Is your Railway database's memory usage high even when it's idle, especially after a backup or dump? Railway bills the page cache as memory. Flanger drops the cache your database isn't using.
Postgres 18 that bills less memory. This is Railway's own Postgres image (postgres-ssl:18, same wrapper.sh, SSL, volume layout and variables as the stock Postgres template) with Flanger as the entrypoint. Flanger watches which cached file data Postgres re-reads and drops the rest.
About Hosting Postgres + Flanger
Railway bills a service's memory as the kernel counts it, and that count includes the page cache: table and index files Postgres has read stay cached and billed after the workload stops touching them. After a backup, a bulk load or a one-off report, a database can sit at several times the memory it needs.
Flanger drops that cache at a pace bounded by the disk's measured IO headroom, and backs off when what it dropped comes back. Postgres starts first and keeps running whatever Flanger does. Signals are passed through, so a redeploy is a clean database system is shut down, not crash recovery. Only file cache is touched, never Postgres memory: dropped cache is re-read from the volume if needed, and dirty pages are never dropped.
Measured on Railway on 2026 Oct 26 with pgbench -i -s 10 (a 157 MB database), 10 minutes after the load:
| value | |
|---|---|
| memory billed at peak, during the load | 574 MB |
| memory billed 10 minutes later | 180 MB |
| page cache still held | 13 MB |
| evicted | 174.5 MB |
| re-read from disk afterwards | 0.23 MB (0.13 %) |
What remains is mostly Postgres's own shared_buffers, which Flanger never touches. Your saving depends on your workload: data that is re-read all the time stays cached.
Measured cost: on write-heavy pgbench TPC-B, 10 strictly interleaved runs each (test container, not Railway) showed no measurable difference: mean 2,692 tps without Flanger and 2,687 with, and median p99 9.8 ms against 7.3 ms. Read-only pgbench showed no difference either. An earlier 5-run comparison had suggested up to 5% lower throughput; the larger sample did not bear it out. If throughput matters more to you than memory, test it on your workload; FLANGER_OFF=1 turns it off.
Over 24 hours on a mostly idle Railway deployment (2026 Nov 01–02, Flanger 0.20.0), memory held at 160 MB with about 1 MB of page cache. Flanger evicted 9 MB in that time, mostly at startup, against 615 MB in 19 hours on the first release, which kept re-reading small catalog files it had just dropped. It used about 0.1% of a CPU core.
Common Use Cases
- Databases whose memory bill stays high after nightly backups,
pg_dumpruns or bulk imports - Databases larger than their working set, where most of the data is rarely read
- Small and side-project databases where page cache is a large share of the bill
Dependencies for Postgres + Flanger Hosting
- A Railway volume mounted at
/var/lib/postgresql/data(included in this template)
Deployment Dependencies
- Image:
ghcr.io/housek/flanger-postgres:18, rebuilt automatically whenever Railway'spostgres-ssl:18base image changes, after tests and a start/stop check pass - Base image: Railway's Postgres SSL image
Implementation Details
Variables match Railway's Postgres template: DATABASE_URL (private network), DATABASE_PUBLIC_URL (TCP proxy), PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, POSTGRES_*, PGDATA.
Optional switches:
FLANGER_DRY_RUN=1: log what would be evicted, evict nothing.FLANGER_OFF=1: kill switch, plain Postgres behaviour.- Without a restart, from a shell in the service:
echo live > /dev/shm/flanger-mode(ordry-run,pause).
Flanger logs one JSON line per event on stderr: start, roots, and a periodic summary with usage, file, evicted_total and reread_total.
Reporting an issue
If something looks wrong, open your service's logs on Railway and paste these into your report:
- the
event="start"line and theevent="roots"line from the start of the log - the last few
event="summary"lines - any
event="warning"orevent="backoff"lines near the problem
They contain versions, sizes, rates and data-folder paths, and no passwords or query contents, but read them before sharing. Set FLANGER_OFF=1 to run plain, in case you need the problem gone first.
Why Deploy Postgres + Flanger on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Postgres + Flanger on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
