Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 3 min read Announcement easyNovice

psql from the browser

psql.sh is a browser-based emulation of Postgres's psql client, built on Neon's WebSocket proxy and serverless driver because browsers can't open raw TCP connections. Each session gets a fresh, isolated database by creating a child branch from a template branch, which yields a connection string almost instantly. Slash commands like \d reuse the Neon SQL Editor's library. The terminal UI was built from scratch instead of using xterm.js, since only a psql session needs emulating. The project is open source.

Assumes: psql basics

Related posts

  • Web-based AI SQL Playground and connecting to Postgres from the browser

    Neon mediumAdept

    Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.

  • Bringing psql’s \d to your web browser

    Neon mediumAdept

    Neon's web SQL Editor now supports psql backslash introspection commands like \d, \l, \dx and \sf, which live in psql's C client code rather than the Postgres server. Instead of compiling psql to WASM with emscripten, the C was translated to JavaScript via RegExp search-and-replace, reimplementations of helpers like sprintf, and a test script comparing output against real psql until every command matched; most fixes involved pointer arithmetic. Because backslash commands must be handled separately, SQL is now split client-side with a small open-source lexer using sticky RegExps that understands quoted identifiers, nested comments, escape and dollar-quoted strings, so only significant semicolons terminate statements.

  • Shipping psql without psql: a pure-TypeScript Postgres client in neonctl

    Neon mediumAdept

    neonctl now embeds a pure-TypeScript reimplementation of psql that activates when no native psql is on the PATH. It covers the REPL, all backslash commands, output formats, connection options, SCRAM and TLS, with no native dependencies, and it was written almost entirely by Claude Code under human review. Correctness rests on a conformance harness that fetches PostgreSQL's own regression scripts and diffs output byte-for-byte against a containerized server across PG 14–18, plus an adversarial security review that caught plausible-looking bugs such as a silent sslmode downgrade and a skippable SCRAM mutual-auth check. Lessons include regression-suite hidden setup (prerequisite tables, injected settings), fixing the first diff mismatch rather than the last, and runtime-dependent TLS behavior (BoringSSL under Bun vs OpenSSL under Node).

  • Live Share: Connect to in-browser PGlite with any Postgres client

    Supabase mediumAdept

    database.build (formerly postgres.new) adds Live Share, which exposes an in-browser PGlite (WASM Postgres) database via a unique connection string usable from psql, pg_dump, ORMs or IDEs. A WebSocket-to-TCP proxy keeps a persistent WebSocket as a reverse tunnel to the browser, while pg-gateway terminates client TCP connections, handles startup, auth and the Postgres SSLRequest upgrade, and reads the TLS SNI server name to route each connection, since Postgres has no HOST header and off-the-shelf proxies can't do SNI routing behind its STARTTLS-style handshake. PGlite's single-connection limit breaks clients that open parallel connections (Prisma shadow DBs, DBeaver defaults), COPY FROM STDIN is unsupported, and multiplexing was rejected due to shared transaction and extended-query state.

  • How Does psql -h pg.neon.tech Work?

    Neon mediumAdept

    Neon's passwordless `psql -h pg.neon.tech` connects to a "Link Proxy", a server that speaks the Postgres wire protocol, rather than to a real Postgres instance. The proxy answers the client's startup message with AuthenticationOk followed by a NoticeResponse, which psql prints as a welcome message containing an auth URL. Visiting that URL opens a control-plane UI where the user picks a project and endpoint. The control plane then sends the connection details for that request ID back to the data-plane proxy, which connects to the chosen compute and relays all traffic to psql.

The quest for software engineering knowledge.

Look:
Layout: