Skip to main content
skill CX Codex

pglite — Claude Code skill: Postgres in the browser via WASM

A skill that hands your coding agent the PGlite API: a WASM build of PostgreSQL 17.4 with storage backends, transactions, live queries and React hooks.

MIT 156 installs ★ 29 updated 2026-08-17

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add oakoss/agent-skills --skill pglite -a claude-code
Open on GitHub

What pglite does

PGlite runs PostgreSQL 17.4 as a WASM module inside the browser, Node.js or Bun, with nothing else installed. The skill gives the agent the call surface: PGlite.create() for an instance, db.query for parameterised statements, db.transaction for an ACID block, db.exec for a multi-statement string. Where data lives depends on the address you pass: memory, idb:// or opfs-ahp://.

Behind SKILL.md sit reference files on setup and storage, queries and transactions, extensions, live queries, React, multi-tab workers and Electric sync. Extensions such as pgvector, pg_trgm and pgcrypto are declared in the create options, not loaded afterwards.

Some edges are hard. OPFS-AHP only runs inside a Web Worker, and Safari lacks the APIs it needs, so idb:// is what is left there. Electric sync moves data one way, from server into a table, and writes never travel back. Two tabs writing without leader election is on the mistake list; PGliteWorker is what the skill points to instead.

What it helps with

  • run a SQL database inside a browser app with no server
  • pick between in-memory, IndexedDB and OPFS storage
  • wrap several statements in one ACID transaction
  • enable pgvector or pg_trgm in an embedded Postgres
  • wire a React hook that re-renders when rows change

Example prompts for the agent

  • Add PGlite to this React app and give me a live query hook for the tasks table.
  • Rewrite this insert with db.sql parameters and wrap it in db.transaction.
  • Set up PGliteWorker with leader election so two tabs don't write at once.

How to install pglite

1Skills CLI (Vercel)

npx skills add oakoss/agent-skills --skill pglite -a claude-code

2Manually: put the files in place

~/.claude/skills/pglite/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/pglite/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about pglite

How do I install the pglite skill in Claude Code?

Run npx skills add oakoss/agent-skills --skill pglite -a claude-code. The skill file lands at ~/.claude/skills/pglite/SKILL.md.

What does the pglite skill do?

It briefs the agent on instance creation, storage backends, queries, transactions, extensions, live queries, React integration, multi-tab workers and Electric sync.

Does PGlite support OPFS in Safari?

No. Safari lacks the OPFS APIs it requires, so idb:// is the storage to use there. OPFS-AHP also only works from a Web Worker.

Source text

SKILL.md · MIT
---
name: pglite
description: |
  PGlite embeds PostgreSQL 17.4 in the browser and Node.js via WASM, under 3MB gzipped. Covers storage backends, queries, transactions, extensions (pgvector, pg_trgm, full-text search), live queries, React integration, multi-tab worker architecture, and Electric sync.

  Use when setting up PGlite, choosing storage backends, writing queries or transactions, configuring extensions, implementing live queries, integrating with React, managing multi-tab workers, or syncing with Electric.
license: MIT
metadata:
  author: oakoss
  version: '1.0'
  source: 'https://pglite.dev/docs'
user-invocable: false
---

# PGlite

## Overview

PGlite is a lightweight WASM build of PostgreSQL 17.4 that runs directly in the browser, Node.js, and Bun with no external dependencies. It provides a full Postgres query engine with extensions, transactions, COPY support, and listen/notify in under 3MB gzipped.

**When to use:** Local-first apps needing a real SQL engine, browser-based analytics, offline-capable PWAs, embedded Postgres for testing, prototyping without a server.

**When NOT to use:** High-concurrency server workloads (use native Postgres), apps requiring full Postgres replication, Safari OPFS storage (not supported), write-heavy multi-tab scenarios without leader election.

## Quick Reference

| Pattern              | API                                              | Key Points                    |
| -------------------- | ------------------------------------------------ | ----------------------------- |
| Create instance      | `PGlite.create(dataDir?, options?)`              | Awaits ready internally       |
| In-memory DB         | `PGlite.create()`                                | Default, ephemeral storage    |
| IndexedDB storage    | `PGlite.create('idb://dbname')`                  | Persists in browser           |
| OPFS storage         | `PGlite.create('opfs-ahp://dbname')`             | Worker only, no Safari        |
| Parameterized query  | `db.query<T>(sql, params)`                       | Returns `QueryResult<T>`      |
| Tagged template      | `db.sql\`SELECT ...\``                           | Auto-parameterized            |
| Multi-statement exec | `db.exec(sqlString)`                             | No params, returns void       |
| Transaction          | `db.transaction(async (tx) => {})`               | Full ACID, use tx.query       |
| Load extension       | `extensions: { vector }` in create               | Loaded at construction        |
| Live query           | `db.live.query(sql, params, cb)`                 | Re-runs on data change        |
| Incremental query    | `db.live.incrementalQuery(sql, params, key, cb)` | Diffs large result sets       |
| Live changes         | `db.live.changes(sql, params, key, cb)`          | Raw insert/update/delete ops  |
| React hook           | `useLiveQuery(sql, params)`                      | Returns `{ rows }` reactively |
| Multi-tab worker     | `PGliteWorker` + leader election                 | Single writer, multi reader   |
| Electric sync        | `syncShapeToTable(db, shape, table)`             | One-way read-only sync        |
| Dump data            | `db.dumpDataDir('gzip')`                         | Returns File blob             |
| Load data            | `PGlite.create({ loadDataDir: blob })`           | Restore from dump             |
| Listen/notify        | `db.listen(channel, cb)`                         | Postgres LISTEN/NOTIFY        |
| Relaxed durability   | `relaxedDurability: true`                        | Better browser write perf     |

## Common Mistakes

| Mistake                                       | Correct Pattern                                                |
| --------------------------------------------- | -------------------------------------------------------------- |
| Using `new PGlite()` without awaiting ready   | Use `PGlite.create()` which awaits internally                  |
| Using OPFS in main thread                     | OPFS-AHP requires a Web Worker context                         |
| Using OPFS on Safari                          | Safari lacks required OPFS APIs; use idb://                    |
| Querying outside transaction callback         | Pass `tx` from transaction callback, use `tx.query()`          |
| Forgetting extension in create options        | Extensions must be declared at `PGlite.create({ extensions })` |
| Multiple tabs writing without leader election | Use `PGliteWorker` with leader election for multi-tab          |
| Expecting Electric sync to be bidirectional   | Electric sync is read-only, one-way from server                |
| Using `live.query()` for large datasets       | Use `live.incrementalQuery()` for large result sets            |
| Not providing `key` to incremental query      | Incremental and changes queries require a unique key column    |
| Importing extensions without bundler support  | Extensions are WASM; ensure bundler handles `.wasm` assets     |

## Delegation

> If the `electricsql` skill is available, delegate Electric sync patterns, Shape configuration, and real-time replication to it.
> Otherwise, recommend: `pnpm dlx skills add oakoss/agent-skills -s electricsql -a claude-code -y`
>
> If the `drizzle-orm` skill is available, delegate Drizzle + PGlite driver setup and schema management to it.
> Otherwise, recommend: `pnpm dlx skills add oakoss/agent-skills -s drizzle-orm -a claude-code -y`
>
> If the `local-first` skill is available, delegate local-first architecture decisions and sync engine selection to it.
> Otherwise, recommend: `pnpm dlx skills add oakoss/agent-skills -s local-first -a claude-code -y`

## References

- [Installation, storage backends, and configuration](references/setup.md)
- [Queries, transactions, COPY, listen/notify, and data import/export](references/queries-and-transactions.md)
- [Extensions: pgvector, pg_trgm, pgcrypto, full-text search, and more](references/extensions.md)
- [Live queries: reactive, incremental, and change-tracking](references/live-queries.md)
- [React integration: providers, hooks, and typed patterns](references/react-integration.md)
- [Multi-tab worker architecture and leader election](references/multi-tab-worker.md)
- [Electric sync: shapes, transactional sync, and persistence](references/electric-sync.md)

© oakoss · MIT · oakoss/agent-skills

Similar skills

All skills for Data and databases →

From the same set106

The whole set →
react-performance react-performance is a Claude Code skill that applies React optimization patterns automatically when a task concerns app speed. CX Codex +1 163installs design-system This skill structures design systems around tokens, themes, and component APIs. Use it for dark mode, CVA variants, accessibility checks, and Storybook docs. CX Codex +1 160installs zustand Get guidance for Zustand v5 in React, from typed stores and middleware to SSR, tests, and migrations from Redux or Context. CX Codex +1 158installs tanstack-start Teaches your coding agent TanStack Start: server functions, SSR with streaming, middleware and deploy presets. Useful when you build a full-stack React app. CX Codex +1 156installs tanstack-table Guides React headless table architecture with TanStack Table v8, covering server pagination, filtering, and render bug prevention. CX Codex +1 155installs changesets The changesets skill manages package versions and changelogs in a monorepo. Use it to coordinate releases and publish packages to npm. CX Codex +1 154installs opentofu Get help writing and reviewing OpenTofu configurations and Pulumi programs. Use the skill to manage infrastructure code, state, and environment setups. CX Codex +1 153installs arktype-validation arktype-validation — a skill for ArkType, where schemas are TypeScript-shaped strings. Covers morphs, scopes and ArkEnv checks for environment variables. Handy for runtime validation that stays close to the type syntax. CX Codex +1 153installs

Project sponsors

Companies that keep this analytics open