Skip to content

Research: PGlite parity with Postgres for the dev runtime #177

Closed

Description

@allisonmahmood

Question

Can one Effect SQL adapter serve both PGlite in the dev runtime and real Postgres on the server, and where does PGlite diverge in ways that matter here? Specifically: transaction and locking semantics with a single embedded connection versus concurrent sessions (lost updates, publish-versus-write races hidden in dev); additive DDL (create table, add nullable or defaulted column, create index) behaving identically; the effect/unstable/sql Postgres client's driver requirements and whether a PGlite-backed SqlClient layer exists or is straightforward; extension support (which extensions PGlite ships, which the Postgres integration's fixture might need to replicate a source schema); Postgres version alignment; startup time and on-disk persistence between patchy dev runs; bundle size and Node version requirements for a dev dependency an agent installs. Primary sources only: the PGlite docs and changelog, the Effect SQL Postgres client source in node_modules/effect, and the Postgres docs on DDL locking.

Recommendation to test against: PGlite is good enough for the dev runtime when concurrency and migrations are also covered by real-Postgres tests in CI, and the dev runtime never forwards an unsupported operation anywhere. Say whether the evidence supports that.

Activity

  1. added
    wayfinder:research
    on Sep 6, 2026
  2. allisonmahmood commented on Sep 6, 2026

    @allisonmahmood
    OwnerAuthor

    Resolved 2026-09-06.

    This preserves #164’s scope and #169’s decision: real capability code, synthetic local rows, no production fallback.

    1. Transactions and locking

    PGlite has one exclusive connection. Whole transactions serialize; commit/rollback works, but PostgreSQL warns that single-user mode cannot reproduce realistic interprocess locking. Scratch probes passed nested rollback and two transactional read-modify-write increments. That does not prove lost-update protection on concurrent Postgres sessions. Nontransactional read/write sequences can still interleave locally.

    Use sql.withTransaction, not manually issued BEGIN mixed with unrelated calls. Require real-Postgres CI with separate connections for lost updates/FOR UPDATE, competing publishes, publish-DDL versus old writers, lock waits/timeouts, and failed-publish rollback. PGlite cannot validate multi-session deadlocks or isolation anomalies. A socket multiplexer does not restore independent database sessions.

    2. Additive DDL

    Scratch probes passed CREATE TABLE, nullable and NOT NULL DEFAULT true additions, ordinary CREATE INDEX, transactional DDL rollback, and old-shaped inserts omitting new columns. This supports the intended subset, not universal equivalence.

    Postgres defaults: existing rows receive NULL without a default; constant defaults avoid row rewrites; volatile defaults such as clock_timestamp() rewrite rows. Locks: ADD COLUMN takes ACCESS EXCLUSIVE, blocking readers/writers; ordinary CREATE INDEX takes SHARE, blocking writers. PGlite hides those waits. CREATE INDEX CONCURRENTLY cannot run inside the transactional migrator. Unique indexes also need old-writer compatibility checks; “additive” does not automatically mean nonbreaking.

    3. Effect SQL adapter

    One SqlClient contract, two driver layers. The checkout lacked node_modules; I installed its pinned 4.0.0-rc.112 in scratch and read the actual Effect SQL sources. PgClient requires node-postgres (pg 8.23.0), clients/pools and pg-cursor. Official PgliteClient already supplies SqlClient, PostgreSQL compilation and transaction acquisition; no bespoke adapter is necessary.

    Two integration gaps are real:

    • Its .query path rejects multi-statement sql.unsafe with 42601 (reproduced), whereas existing migrations use that form. Emit individual statements inside one transaction; do not split SQL on semicolons.
    • Normalize row codecs: PGlite’s int8 is number/bigint depending on magnitude, versus pg’s string; DATE parsed as UTC versus local midnight in the probe. Its stream materializes results, unlike pg’s cursor.

    4. Extensions and source-schema fixtures

    The catalog lists 33 bundled contrib extensions: amcheck, auto_explain, bloom, btree_gin, btree_gist, citext, cube, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, intarray, isn, lo, ltree, pageinspect, pg_buffercache, pg_freespacemap, pg_stat_statements, pg_surgery, pg_trgm, pg_visibility, pg_walinspect, pgcrypto, seg, tablefunc, tcn, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp; plus the live plugin. The package additionally contains moddatetime and uncatalogued extension archives; shipped bytes alone are not a support guarantee.

    Nine catalogued extensions require separate packages: pgvector, AGE, pg_hashids, pg_ivm, pg_textsearch, pg_uuidv7, pgmq, pgTAP, PostGIS. Load declared WASM extensions at startup, then CREATE EXTENSION. PostGIS remains experimental. postgres_fdw/dblink are not shipped; background workers are disabled.

    Fixtures may need extension-defined types, operators, defaults and indexes—not just column names. Required extensions cannot be determined without the source schema/pg_extension metadata. Explicitly allow supported mappings; reject everything else locally, never substitute types or forward calls.

    5. Postgres version alignment

    PGlite 0.5.8, released 2026-08-26, reports PostgreSQL 18.3 in the probe, matching the 0.5.0 upgrade. The repo pins [email protected], not an identical engine release. Pin PGlite explicitly alongside the runtime; run parity checks against the deployed Postgres version and every supported source version. Live server/source versions were not queried; establish them through SELECT version() metadata. PGlite minor upgrades may require dump/restore, not datadir reuse.

    6. Startup and persistence

    NodeFS persists a directory; memory mode does not. Linux/x64, Node 24.20.0, three fresh-process create/reopen pairs: import-to-ready 1.051–1.063 seconds for empty directories, 0.166–0.171 seconds reopening. Rows and added columns survived clean close/reopen. Tiny-fixture measurements, not universal startup guarantees.

    Use one owner per directory, await readiness and close cleanly. Default startup settings disable fsync (-F): persistent does not mean production-equivalent crash durability. Keep fixtures recreatable.

    7. Bundle size and Node requirements

    Measured published 0.5.8 tarball: 8,791,923 bytes compressed; 25,437,263 unpacked, before Effect and external extensions. Marketing’s core gzip size is not installation size. No published engines floor; release CI covers Node 20–24. Keep Patchy’s Node >=22 requirement; this experiment used 24.20.0.

    Verdict: amend. PGlite is suitable for the bounded dev runtime, with real-Postgres concurrency/migration CI and fail-closed fixtures. Add explicit adapter/codec compatibility, version/extension pins and recreatable persistence. Evidence supports shared capability code—not a drop-in driver swap or production-parity claim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:research

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions