ConfigsApr 20, 2026·3 min read

PGlite — Embeddable Postgres in WebAssembly

PGlite is an embeddable PostgreSQL build that runs in the browser, Node.js, and Bun via WebAssembly, giving you a full Postgres engine under 3MB with real-time reactive queries.

Introduction

PGlite packages a real PostgreSQL engine into a WebAssembly build that runs directly in the browser or server-side JavaScript runtimes. It provides full SQL compatibility with Postgres in a lightweight embeddable package, ideal for local-first apps, testing, and prototyping.

What PGlite Does

  • Runs a complete PostgreSQL instance in the browser with no server required
  • Works in Node.js, Bun, and Deno for server-side embedded use cases
  • Supports persistent storage via IndexedDB in the browser or filesystem on the server
  • Provides reactive live queries that re-execute when underlying data changes
  • Includes extension support for pgvector, PostGIS, and full-text search

Architecture Overview

PGlite compiles the PostgreSQL C source code to WebAssembly using Emscripten. The resulting WASM module runs in any JavaScript environment with a virtual filesystem layer that maps to IndexedDB (browser) or the real filesystem (Node.js). A TypeScript wrapper provides the query API, connection pooling, and the reactive live-query layer built on top of logical replication.

Self-Hosting & Configuration

  • Install via npm as a standard JavaScript dependency
  • No external PostgreSQL server or Docker container needed
  • Configure storage backend (in-memory, IndexedDB, or filesystem) at initialization
  • Load extensions like pgvector by importing the corresponding PGlite extension package
  • Works in serverless environments including Cloudflare Workers and Vercel Edge Functions

Key Features

  • Full PostgreSQL wire protocol compatibility in under 3MB compressed
  • Reactive live queries that push updates when data changes
  • Extension ecosystem including pgvector for AI embeddings
  • Zero-dependency local-first storage for offline-capable applications
  • TypeScript-first API with full type inference

Comparison with Similar Tools

  • sql.js (SQLite WASM) — SQLite compiled to WASM; simpler but lacks Postgres features like JSONB, window functions, and extensions
  • libSQL / Turso — SQLite fork with server sync; different SQL dialect and extension model
  • DuckDB WASM — Analytical query engine in WASM; optimized for OLAP, not transactional workloads
  • CockroachDB — Distributed Postgres-compatible database; requires server infrastructure
  • SurrealDB — Multi-model database with embedded mode; uses its own query language, not standard SQL

FAQ

Q: Is PGlite a full PostgreSQL implementation? A: Yes, PGlite compiles the actual PostgreSQL source code to WebAssembly. It supports the vast majority of PostgreSQL features and SQL syntax.

Q: Can I use PGlite for production applications? A: PGlite is well-suited for local-first apps and embedded use cases. For multi-user server workloads, a traditional PostgreSQL deployment is recommended.

Q: How large is the PGlite WASM bundle? A: The compressed bundle is under 3MB, making it practical for browser-based applications.

Q: Does PGlite support migrations? A: PGlite runs standard PostgreSQL DDL, so any migration tool that generates SQL (Drizzle, Prisma, raw SQL) works with it.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets