{"slug": "db4-is-open-source-local-rag-on-postgres-in-a-browser-tab", "title": "Db4 is open source: local RAG on Postgres in a browser tab", "summary": "Max Abrahamsson released db4, a local RAG tool that runs real Postgres via PGlite (Postgres compiled to WebAssembly) inside a browser tab, under the MIT license on October 20, 2026, the same day he shut down the hosted relay service. db4 stores vectors in the tab's IndexedDB, performs cosine similarity search in plain SQL, and exposes an MCP server that LM Studio or Claude Desktop can call with a local embedding model, while psql, DBeaver, TablePlus and ORMs connect over the Postgres wire protocol through a self-run relay that stores no data. Abrahamsson wrote that \"db4 makes more sense as something you own than as something you rent from me,\" and existing databases remain in users' browsers, though old *.pg.db4.app connection strings no longer resolve.", "body_md": "October 20, 2026  \n\n # db4 is open source: local RAG on Postgres in a browser tab\n\n db4 runs real Postgres inside a browser tab, with vector search in plain SQL, so a local LLM can do RAG over your data and nothing leaves your machine. psql, ORMs and MCP clients connect too. Now MIT-licensed on GitHub.\n\n   *Above: **RAG with a model running locally in LM Studio**, against a\ndatabase that lives in a browser tab, with `psql` first to show it’s real Postgres. I recorded and edited it with\n[rec4](https://rec4.app/?utm_source=lab4-blog&utm_medium=post&utm_campaign=db4-open-source), the AI screen\nrecorder for Mac we’re building at lab4. If you ship developer tools, it’s built for exactly this kind of video.*\n\nWhat if your RAG stack were just a browser tab and a model on your laptop?\n\nThat’s **db4**. It runs real Postgres ([PGlite](https://github.com/electric-sql/pglite),\nPostgres compiled to WebAssembly) inside the tab and keeps it in the browser’s own storage. An MCP client like LM Studio or\nClaude Desktop calls db4’s MCP server, which embeds your text with a local LM Studio\nembedding model and stores the vectors in the tab. Search is cosine similarity written in\nplain SQL, in a [community app](https://github.com/maxabrahamsson/db4app-community-apps/tree/main/apps/rag-mcp) you can read in one sitting. There’s no vector database\nservice and no cloud account, and with a local model nothing leaves your machine. Because it speaks\nthe standard Postgres wire protocol, `psql`, DBeaver, TablePlus and your ORM can connect\nto the same database.\n\nToday db4 is **open source under the MIT license**, and the hosted service is retired.\n\n[**github.com/maxabrahamsson/db4app** →](https://github.com/maxabrahamsson/db4app)\n\n## How it works\n\n```\npsql / DBeaver / ORM / MCP server\n        │  Postgres wire protocol\n        ▼\n     relay  (routes bytes, stores nothing)\n        │  WebSocket\n        ▼\n browser tab ── Postgres (PGlite, WASM) ── IndexedDB\n```\n\nThe interesting part is the **trust model**. The browser tab is the owner of the data.\nThe auth token, read-only mode, query guards and per-app schema isolation are all\nenforced *in the tab*, under the user’s control. The relay in the middle is plain transport:\nit matches a connection ID to the right tab and forwards bytes. It keeps no data and\nmakes no access decisions. It does see the query traffic it forwards, which is one more\nreason to run your own.\n\nThat inverts the usual setup. Normally the server holds your data and your browser\nborrows a view of it. With db4 the browser holds the data, and servers only get to talk\nto it when you let them.\n\n## Why open source, and why now\n\nSince late 2025 I’ve run a public relay so anyone could open the site and connect `psql`\nto their tab within seconds. On **October 20, 2026** I shut it down.\n\ndb4 makes more sense as something you own than as something you rent from me. The\nrelay is a single small Node process. When you run it yourself, on your laptop, your\nhomelab or a $5 VPS, the whole chain from client to data is yours.\n\n- **Code:**[github.com/maxabrahamsson/db4app](https://github.com/maxabrahamsson/db4app) (MIT)\n- **Website:**[db4.lab4.app](https://db4.lab4.app) . The app still works there: the\ndatabase, SQL editor and community apps all run in your tab. External clients need a\nrelay, which you now run yourself.\n- **Your data:** if you used the hosted version, your databases are where they always\nwere, in your browser. Nothing was stored on the relay, so nothing was lost. Old`*.pg.db4.app` connection strings no longer resolve, and the relay indicator shows offline.\nThe fix is one step: run a relay (below), then set**Database → Relay server → Custom relay\nURL** to`ws://localhost:8787/agent` .\n\nRunning it locally takes a minute:\n\n```\ngit clone --recurse-submodules https://github.com/maxabrahamsson/db4app.git\ncd db4app && npm install\nnpm run relay   # relay: :8787 (WebSocket) + :6543 (Postgres)\nnpm run dev     # web app: http://localhost:5173\n```\n\nThen copy the connection ID and token from the Database page:\n\n```\npsql \"postgres://postgres:YOUR_TOKEN@localhost:6543/YOUR_CONNECTION_ID\"\n```\n\n**If you put the relay on a server:** the auth token is the only thing standing between\nthe internet and your tab’s database, so treat it like a password. Put the relay behind\nTLS (a reverse proxy serving `wss://`), and don’t open the Postgres port (6543) publicly\nunless you need to. An SSH tunnel or a firewall allowlist is safer. The\n[self-hosting guide](https://github.com/maxabrahamsson/db4app/blob/main/docs/self-hosting.md)\ncovers TLS and rate limits.\n\nThere’s also a [Dockerfile for the relay](https://github.com/maxabrahamsson/db4app#relay-with-docker),\nan MCP server ([`npx db4app-mcp-server`](https://www.npmjs.com/package/db4app-mcp-server)) for\nClaude Desktop, LM Studio and friends, and a [small desktop app](https://github.com/maxabrahamsson/db4app/tree/main/packages/relay-app)\nthat wraps a single-user relay.\n\n## What you can build with it\n\nA few things db4 is already good at, and a few I’d love someone to try:\n\n- **Local-first RAG.** Store embeddings in the tab, query them from a local model\nthrough MCP. Your documents never touch a third-party service.\n- **A private database for an AI agent.** Give an agent a real Postgres it can create\ntables in, query, and reset, inside a tab you can close. It’s a sandbox you can see.\n- **Teaching SQL.** Every student gets a real Postgres with zero install, and they can\nstill practice with`psql` and real GUI clients, not just a web textbox.\n- **Prototyping and demos.** Spin up a schema, point your ORM or BI tool at it, and\nthrow it away. No containers, no cloud accounts.\n- **Offline field tools.** The database lives with the app and works without a\nnetwork. Connect a laptop’s tools to it when you’re back.\n- **“Bring your own database” web apps.** Apps that store user data in the user’s\nbrowser, but still speak standard Postgres so power users can inspect and own it.\n\nSome ideas that are wide open:\n\n- **pgvector.** PGlite ships the extension; wiring it in would give the RAG app real\nvector columns and indexes instead of arrays. A good first PR.\n- A **browser-tab replica** that syncs from a real Postgres for fast local analytics.\n- **Peer-to-peer relays** , so two tabs can query each other with no relay in the middle.\n- **Per-app capability tokens** , so you can grant an agent read access to one schema\nfor one hour.\n- More **community apps** : small, self-contained schemas plus instructions that anyone\ncan install into their tab ([community apps repo](https://github.com/maxabrahamsson/db4app-community-apps) ).\n\n## Come build with it\n\nIf any of this sparks something, clone it, break it, and tell me what you made. Issues\nand PRs are welcome, especially new community apps, relay hardening, and wild use cases\nI haven’t thought of.\n\n[**Star or fork db4 on GitHub** →](https://github.com/maxabrahamsson/db4app)", "url": "https://wpnews.pro/news/db4-is-open-source-local-rag-on-postgres-in-a-browser-tab", "canonical_source": "https://lab4.app/blog/db4-is-now-open-source/", "published_at": "2026-10-20 19:51:04+00:00", "updated_at": "2026-10-20 20:16:56.151260+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-tools", "ai-agents", "agent-protocols", "developer-tools"], "entities": ["db4", "Max Abrahamsson", "PGlite", "Postgres", "LM Studio", "Claude Desktop", "lab4", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/db4-is-open-source-local-rag-on-postgres-in-a-browser-tab", "markdown": "https://wpnews.pro/news/db4-is-open-source-local-rag-on-postgres-in-a-browser-tab.md", "text": "https://wpnews.pro/news/db4-is-open-source-local-rag-on-postgres-in-a-browser-tab.txt", "jsonld": "https://wpnews.pro/news/db4-is-open-source-local-rag-on-postgres-in-a-browser-tab.jsonld"}}