build(pglite): cap max_wal_size at 128MB in the wasm module

PGlite splices a fixed list of -c settings into every start and never
reads postgresql.conf or postgresql.auto.conf on restart (ALTER SYSTEM
writes to the wrong directory and pg_reload_conf is a no-op without a
postmaster), so the only way to lower max_wal_size is that list. With
128MB, a CHECKPOINT trims pg_wal from 405 MB to 134 MB locally instead
of letting it grow to the 1 GB default.
This commit is contained in:
Deluan 2026-09-05 01:32:06 -04:00
commit d66aa23f88
3 changed files with 14 additions and 0 deletions

View file

@ -11,6 +11,11 @@ electric-sql/postgres-pglite, branch REL_17_5_WASM-pglite). Clone it to /tmp/pgl
- `wasi-c.diff` — makes the forced `-fPIC` in the compiler wrapper overridable (`PGLITE_PIC`). NOTE: the matching
`-fpic` in `postgresql-src/wasm-build/build-pgcore.sh` (cloned at build time) is not covered by a diff here; the
`-fno-pic` experiment did not take effect and is unmeasured.
- `max_wal_size.diff` — goes in `patches/postgresql-pglite/` as `src-include-port-wasm_common.h.zz-max-wal-size.diff`
(it must sort after pglite4j's own `wasm_common.h` patch). PGlite splices a fixed list of `-c` settings into
every start (`WASM_PGOPTS`), never reads `postgresql.conf`/`postgresql.auto.conf` on restart, and `pg_reload_conf()`
is a no-op without a postmaster, so `ALTER SYSTEM` cannot change anything. Adding `max_wal_size=128MB` to that
list caps `pg_wal` at ~130 MB instead of 1 GB once a `CHECKPOINT` runs.
- `message_context_reset.diff` — goes in `patches/pglite-wasm/`. The fork stubs `MemoryContextResetAndDeleteChildren`
(removed in PostgreSQL 17) as an empty macro, so `MessageContext` is never reset and every wire message leaks its
parse/plan state (~10 KB per statement; a library scan reached 15 GB). The patch maps it to `MemoryContextReset`.

View file

@ -0,0 +1,9 @@
--- a/src/include/port/wasm_common.h
+++ b/src/include/port/wasm_common.h
@@ -63,5 +63,6 @@
"-c", "synchronous_commit=on",\
"-c", "wal_buffers=4MB",\
"-c", "min_wal_size=80MB",\
+ "-c", "max_wal_size=128MB",\
"-c", "shared_buffers=128MB"

Binary file not shown.