diff --git a/db/pglite/build/README.md b/db/pglite/build/README.md index b096899b6..64333cbac 100644 --- a/db/pglite/build/README.md +++ b/db/pglite/build/README.md @@ -11,6 +11,9 @@ 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. +- `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`. - `clear_error_portals.diff` — goes in `patches/pglite-wasm/`. A PostgreSQL ERROR traps the wasm instance, which skips every PG_CATCH, so the active portal is never marked failed and the next statement fails with "cannot drop active portal". Wrapping `AbortCurrentTransaction()` in `clear_error()` with diff --git a/db/pglite/build/message_context_reset.diff b/db/pglite/build/message_context_reset.diff new file mode 100644 index 000000000..d8e5a7fe8 --- /dev/null +++ b/db/pglite/build/message_context_reset.diff @@ -0,0 +1,12 @@ +--- a/pg_main.c ++++ b/pg_main.c +@@ -28,7 +28,8 @@ + + // globals + +-#define MemoryContextResetAndDeleteChildren(...) ++// PG17 dropped this macro; the no-op stub leaked every message's parse/plan state. ++#define MemoryContextResetAndDeleteChildren(ctx) MemoryContextReset(ctx) + // #define SpinLockInit(...) + + diff --git a/db/pglite/pglite.go b/db/pglite/pglite.go index 46a5a35c5..a329e5fa3 100644 --- a/db/pglite/pglite.go +++ b/db/pglite/pglite.go @@ -403,6 +403,9 @@ func (pg *PGlite) startBridge() error { // DataDir is the host directory holding the cluster. func (pg *PGlite) DataDir() string { return pg.dataDir } +// MemorySize reports the wasm linear memory size in bytes; it only ever grows. +func (pg *PGlite) MemorySize() uint64 { return uint64(pg.mod.Memory().Size()) } + // Connections reports how many client connections the bridge has accepted. func (pg *PGlite) Connections() int64 { return pg.connections.Load() } diff --git a/db/pglite/pglite.wasi.gz b/db/pglite/pglite.wasi.gz index b406c1504..ce1f6c6a8 100644 Binary files a/db/pglite/pglite.wasi.gz and b/db/pglite/pglite.wasi.gz differ