electric-pglite is a free, open source databases project written in TypeScript and released under Apache-2.0. It has 16,268 GitHub stars, 475 forks and 163 open issues, and was last pushed 2 days ago. On this registry it ranks #46 of 207 tracked projects in Databases, with 5 head-to-head comparisons available.

What is electric-pglite?

electric-pglite is PGlite, the WebAssembly build of PostgreSQL packaged as a TypeScript client library that runs a real Postgres database inside the browser, Node.js, Bun or Deno, aimed at developers building reactive, realtime and local-first applications who want Postgres itself rather than a lookalike.

What it is

PGlite is the WASM build of Postgres from Electric, published under the Apache-2.0 licence and distributed as the npm package @electric-sql/pglite. It compiles PostgreSQL to WebAssembly and wraps it in a TypeScript client library so that a database can run inside a JavaScript environment with no other dependencies installed, in a bundle that is only 3 MB gzipped. Instance state can be ephemeral and in-memory, or persisted either to the file system on Node, Bun and Deno or to indexedDB in the browser.

The problem it solves is the operational weight of Postgres as a separate service: ordinarily the database is a server process that an application connects to over a socket, which is a poor fit for a browser tab, a local-first app or a single-file tool. PGlite moves the database into the application's own process. Because Postgres normally forks a process per connection and code compiled with Emscripten cannot fork, PGlite builds on Postgres's single-user mode and adds an input/output pathway that lets a JavaScript host drive the compiled engine. It therefore replaces an installed Postgres instance for embedded use, and it does so without a Linux virtual machine, which is how earlier "Postgres in the browser" projects worked.

Key capabilities

  • Imports a working Postgres into an application with import { PGlite } from "@electric-sql/pglite", after which db.query("select 'Hello world' as message;") returns the usual rows result.
  • Offers three storage modes: a default in-memory database, file-system persistence through new PGlite("./path/to/pgdata"), and browser persistence through an indexedDB URL such as new PGlite("idb://my-pgdata").
  • Supports a range of Postgres extensions, with pgvector and PostGIS named explicitly.
  • Exposes a node-postgres-compatible connection object since v0.5.13: createPgConfig from @electric-sql/pglite/node-postgres can be handed to pg's Client or Pool, and cursors from pg-cursor work against it.
  • Installs through the native package manager on each target runtime, using npm install @electric-sql/pglite on NodeJS, bun install on Bun and deno add npm:@electric-sql/pglite on Deno, or through a CDN such as jsDelivr in the browser.
  • Can be built from source, a two-part process that compiles the Postgres WASM module with Docker and then builds the TypeScript packages with Node v20 or above and pnpm.

Who uses it and how

  • Browser applications that need a genuine relational database on the client and persist it to indexedDB across sessions, in keeping with the local-first pattern the project targets.
  • Node, Bun and Deno applications and command-line tools that embed the database in-process and persist it to a directory on disk rather than connecting to a server.
  • Teams with existing node-postgres code that pass a createPgConfig result into a pg Client or Pool to reuse their queries, pools and cursor logic unchanged.
  • Workloads that benefit from an ephemeral in-memory database spun up inside a single process, since no external service or dependency has to be installed alongside it.
  • Single-user contexts, which is the shape the engine currently supports: one user and one connection per instance.

Getting started

Install the package into the project with npm install @electric-sql/pglite, or the Bun and Deno equivalents, then construct const db = new PGlite() for an in-memory database; browser users can equally import the library from the jsDelivr CDN. Full documentation and user guides are hosted at pglite.dev.

How it compares

The supplied facts name no competing tools or paid products, so electric-pglite stands alone in this registry rather than being measured against alternatives here. The only contrast the README draws is a technical one with earlier "Postgres in the browser" efforts that shipped a Linux virtual machine, which PGlite does not.

When to use it — and when not to

Choose it when a single process needs a real Postgres and the alternative is installing and running a server, and be prepared to manage the storage layer yourself, whether that is a file-system path on Node, Bun or Deno or an indexedDB database in the browser. It is the wrong pick for multi-client or concurrent workloads: the README states plainly that PGlite is single user and single connection, so there is no server to accept many connections and no replication story in the material provided. Outside the README, documentation lives on the project site rather than in the repository, so teams needing depth should budget time for pglite.dev.

project readme (upstream, from github) — read inline

PGlite logo

PGlite - the WASM build of Postgres from Electric.
Build reactive, realtime, local-first apps directly on Postgres.

License - Apache 2.0 Status - Alpha Chat - Discord

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.

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:

import { PGlite } from "@electric-sql/pglite";

or using a CDN such as JSDeliver:

import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";

Then for an in-memory Postgres:

const db = new PGlite()
await db.query("select 'Hello world' as message;")
// -> { rows: [ { message: "Hello world" } ] }

or to persist the database to indexedDB:

const db = new PGlite("idb://my-pgdata");

Node/Bun/Deno

Install into your project:

NodeJS

npm install @electric-sql/pglite

Bun

bun install @electric-sql/pglite

Deno

deno add npm:@electric-sql/pglite

To use the in-memory Postgres:

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:

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):

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, programs compiled with Emscripten - a C to WebAssembly (WASM) compiler - cannot fork new processes, and operates strictly in a single-process mode. As a result, PostgreSQL cannot be directly compiled to WASM for conventional operation.

Fortunately, PostgreSQL includes a "single user mode" primarily intended for command-line usage during bootstrapping and recovery procedures. Building upon this capability, PGlite introduces an input/output pathway that facilitates interaction with PostgreSQL when it is compiled to WASM within a JavaScript environment.

Limitations

  • PGlite is single user/connection.

How to build PGlite and contribute

The build process of PGlite is split into two parts:

  1. Building the Postgres WASM module.
  2. Building the PGlite client library and other TypeScript packages.

Docker is required to build the WASM module, along with Node (v20 or above) and pnpm for package management and building the TypeScript packages.

To start checkout the repository and install dependencies:

git clone --recurse-submodules https://github.com/electric-sql/pglite
cd pglite
pnpm install

To build everything, we have the convenient pnpm build:all command in the root of the repository. This command will:

  1. Use Docker to build the Postgres WASM module. The artifacts produced by this step are then copied to /packages/pglite/release.
  2. Build the PGlite client library and other TypeScript packages.

To only build the Postgres WASM module (i.e. point 1 above), run

pnpm wasm:build

If you don't want to build the WASM module and assorted WASM binaries from scratch, they are generated automatically on Github after each successful PR merge. You can download the latest binaries by going to the last successfully merged PR and clicking the link after the comment Interim build files:. Extract the files and place them under packages/pglite/release in your local repo copy.

To build all TypeScript packages (i.e. point 2 of the above), run:

pnpm ts:build

This will build all packages in the correct order based on their dependency relationships. You can now develop any individual package using the build and test scripts, as well as the stylecheck and typecheck scripts to ensure style and type validity.

Or alternatively to build a single package, move into the package directory and run:

cd packages/pglite
pnpm build

When ready to open a PR, run the following command at the root of the repository:

pnpm changeset

And follow the instructions to create an appropriate changeset. Please ensure any contributions that touch code are accompanied by a changeset.

Acknowledgments

PGlite builds on the work of Stas Kelvich of Neon in this Postgres fork.

Sponsors

Big shoutout to everybody supporting us!

Blacksmith

License

PGlite is dual-licensed under the terms of the Apache License 2.0 and the PostgreSQL License, you can choose which you prefer.

Changes to the Postgres source are licensed under the PostgreSQL License.

Frequently asked questions

Is electric-pglite free to use?

electric-pglite is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does electric-pglite do?

Embeddable Postgres with real-time, reactive bindings.

What is electric-pglite written in?

electric-pglite is primarily written in TypeScript. Its source is publicly available at https://github.com/neondatabase/electric-pglite, and it has 16,268 GitHub stars.