Distro News

PGlite brings embedded PostgreSQL to browsers via WebAssembly

Key Takeaway

PGlite compiles PostgreSQL to WebAssembly, enabling serverless SQL queries with persistence in browsers and JavaScript runtimes without requiring a separate database process.

Summary

Electric has released PGlite, an open-source embedded PostgreSQL database that runs entirely within WebAssembly, eliminating the need for a separate server process. The project adapts PostgreSQL's single-user operating mode to function in browser and JavaScript runtime environments including Node.js, Bun, and Deno, with data persistence available through IndexedDB in browsers or filesystem storage elsewhere.

PGlite targets local-first applications, browser-based development tools, and use cases requiring relational storage without operational database infrastructure. It supports PostgreSQL extensions including pgvector and PostGIS, offers reactive bindings for change-responsive applications, and maintains compatibility with node-postgres clients. The software is dual-licensed under Apache 2.0 and the PostgreSQL License.

Architecture and runtime model

  • WebAssembly compilation: PostgreSQL is compiled to WebAssembly, allowing the full database engine to execute within browser sandboxes and JavaScript runtimes without native installation or background services.
  • Single-user mode adaptation: PGlite repurposes PostgreSQL's single-user backend, bypassing the conventional postmaster multiprocessing architecture to operate as an embedded library rather than a client-server system.
  • Persistence mechanisms: Browser deployments use IndexedDB for cross-session storage, while non-browser environments can write to the host filesystem; in-memory operation remains available for ephemeral workloads.
  • Extension support: The WebAssembly build includes working support for pgvector (vector similarity search) and PostGIS (geospatial data), indicating substantial compatibility with PostgreSQL's extension framework.
  • Reactive bindings and client compatibility: PGlite provides asynchronous JavaScript APIs and reactive integrations, plus drop-in compatibility with node-postgres clients through a matching interface.

Why it matters

PGlite lowers the operational barrier for applications that need full SQL semantics and PostgreSQL compatibility without managing database infrastructure, particularly relevant for offline-capable web applications and edge deployments. Its node-postgres compatibility and support for popular extensions like pgvector position it as a practical alternative to SQLite for JavaScript developers who require PostgreSQL-specific features or migration paths to server-based PostgreSQL in production.

Original reference: www.linuxlinks.com →