electric-sql /pglite
Embeddable Postgres with real-time, reactive bindings.
★ 16,277⑂ 475👁 64⑃ 725● 443▤ 577
+2
Daily
16,277
stars
475
forks
64
watchers
725
prs
443
issues
577
releases
README
PGlite - the WASM build of Postgres from Electric.
Build reactive, realtime, local-first apps directly on Postgres.
--
PGlite - Postgres in WASM
!PGlite
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js, Bun and Deno, with no need to install any other dependencies. It is only 3mb gzipped and has support for many Postgres extensions, including pgvector and PostGIS.
javascript
import { PGlite } from "@electric-sql/pglite";
const db = new PGlite();
await db.query("select 'Hello world' as message;");
// - { rows: [ { message: "Hello world" } ] }
It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun/Deno) or indexedDB (Browser).
Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.
For full documentation and user guides see pglite.dev.
Browser
It can be installed and imported using your usual package manager:
js
import { PGlite } from "@electric-sql/pglite";
or using a CDN such as JSDeliver:
js
import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";
Then for an in-memory Postgres:
js
const db = new PGlite()
await db.query("select 'Hello world' as message;")
// - { rows: [ { message: "Hello world" } ] }
or to persist the database to indexedDB:
js
const db = new PGlite("idb://my-pgdata");
Node/Bun/Deno
Install into your project:
NodeJS
bash
npm install @electric-sql/pglite
Bun
bash
bun install @electric-sql/pglite
Deno
bash
deno add npm:@electric-sql/pglite
To use the in-memory Postgres:
javascript
import { PGlite } from "@electric-sql/pglite";
const db = new PGlite();
await db.query("select 'Hello world' as message;");
// - { rows: [ { message: "Hello world" } ] }
or to persist to the filesystem:
javascript
const db = new PGlite("./path/to/pgdata");
pg (node-postgres)
Since v0.5.13, PGlite exposes a connection object that you can directly pass to pg (node-postgres) modules (clients):
javascript
import { createPgConfig } from '@electric-sql/pglite/node-postgres'
import { Client, Pool } from 'pg'
import Cursor from 'pg-cursor'
// use with pg Client
const pgConfig1 = createPgConfig()
const client = new Client(pgConfig1)
await client.connect()
await client.query(
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
name TEXT
);
)
// or with Pool
const pgConfig2 = createPgConfig()
const pool = new Pool(pgConfig2)
const conn = await pool.connect()
await conn.query(
CREATE TABLE IF NOT EXISTS test (
id SERIAL PRIMARY KEY,
name TEXT
);
)
// or even with Cursor from pg-cursor
const cursor = client.query(new Cursor('SELECT FROM items;'))
How it works
PostgreSQL typically operates using a process forking model; whenever a client initiates a connection, a new process is forked to manage that connection. However, progTop issues
#87React native support 45 comments · 2024-05-07#916PostGIS improvements43 comments · 2026-03-17#470Rust Bindings23 comments · 2024-12-14#89PGlite bindings for other runtimes?18 comments · 2024-05-15#1120Feature request: Nitro 3 support (`unwasm` export condition)16 comments · 2026-10-06#409Invalid FS bundle size14 comments · 2024-10-28#9Support for opfs in browsers via wasmfs13 comments · 2024-02-23#322Running pglite in the browser: `Error: createRequire is not a function`12 comments · 2024-09-14
Discussions
#1119IOTA Watch: testing per-project quotas and row ownership with PGlite0 comments · 2026-10-06#1075Using PGlite to make a Postgres RLS failure reproducible in 2 seconds (no Docker, no credentials)3 comments · 2026-08-07#987Reliability and data integrity2 comments · 2026-05-08#959YouTube: PGlite React Live Queries in Multi Tab Worker TypeScript Vite0 comments · 2026-04-01#950Does PGlite work with pg-promise and node-postgres?2 comments · 2026-03-30#930How does pglite benchmark against sqlite on node?1 comments · 2026-03-20#912Is it possible to set max_wal_size? How to optimize RAM usage with IndexedDB?2 comments · 2026-03-11#893Encrypted VFS for PGlite (NodeFS)0 comments · 2026-02-22
Latest release
@electric-sql/[email protected] @electric-sql/[email protected] 2026-11-10Patch Changes - 51aa2a0: Bump version of newest extensions