PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 3.7mb gzipped.
PGlite - the WASM build of Postgres from ElectricSQL.
Build reactive, realtime, local-first apps directly on Postgres.
PGlite - Postgres in WASM
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.
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 a 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:
Building the Postgres WASM module.
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 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:
Use Docker to build the Postgres WASM module. The artifacts from this are then copied to /packages/pglite/release.
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, you can download them from a comment under the most recently merged PR, labeled as interim build files, and place them under packages/pglite/release.
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.
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 3.7mb gzipped.
The npm package @electric-sql/pglite receives a total of 0 weekly downloads. As such, @electric-sql/pglite popularity was classified as not popular.
We found that @electric-sql/pglite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 3 open source maintainers collaborating on the project.
Package last updated on 21 Jan 2025
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
By Kirill Boychenko, Peter van der Zee - Jan 29, 2025