pg-llm-usodb: The PostgreSQL Server That Makes Up Its Own Database

It speaks the wire protocol, fools real clients, and uses an LLM plus virtual state to fabricate tables, rows, and metadata on demand.

8 min read • View on GitHub • More from trkbt10

A PostgreSQL client terminal sends a query through a wire into a server cabinet, but the cabinet opens onto a tiny stage where a masked performer assembles rows from handwritten cards. It explains the project’s central trick: real protocol, invented database.
The lie begins at the protocol boundary. The client gets a believable PostgreSQL session, while the server improvises the data behind the curtain.

pg-llm-usodb … LLMが"それっぽい"応答を捏造するPostgreSQL互換サーバー。「LLMエージェントが得意な実装・よく理解している概念」を語る入口に

Key Takeaways

The Database That Isn’t There

The first trick is that this is not a database app pretending to be one. It is a real PostgreSQL server on the wire, which means tools like psql and ORM clients can connect and start behaving normally. The surprise is that the server then improvises the rest.

That matters because most mock databases ask developers to script the answers up front. pg-llm-usodb flips the burden around. The client’s queries become the input that shapes the fiction.

A hedcut-style portrait of Terukichi derived from the verified GitHub avatar. It identifies the project creator and grounds the article in a real source image.

Why This Is More Than a Toy Mock

ApproachInputOutputStateClient compatibilityBest use case
Traditional SQL mockTest codePredefined rows or errorsManual or absentLow, often adapter-specificUnit tests with fixed expectations
Text-to-SQL systemNatural languageSQL textUsually noneIndirectQuery generation and assistants
pg-llm-usodbSQL over PostgreSQL wire protocolFabricated rows, metadata, and schemaVirtualDbState plus JSONL logHigh, real PostgreSQL clients can connectAgent stress testing and rapid prototyping
Real databaseSQL over PostgreSQL wire protocolPersisted truth from storageDurable engine stateHighProduction or serious local development

The table above is the point. This project is not trying to outgrow mocks by being more configurable. It is trying to outgrow them by being protocol compatible. That means you can aim a real app at it and see how far the illusion holds.

The Three-Layer Stack

A query is not just answered here. It is classified, routed, remembered, and recorded before the client ever sees a row.

The architecture is intentionally split into three layers. The PostgreSQL adapter handles the wire protocol. The LLM service layer decides what kind of response to invent. The utility layer keeps an append-only trail of what happened.

The Query Router: Fast Path, Introspection, Mutation

A close-up machine with three branching chambers turns a query into one of three routes: fast path, introspection, or mutation. A ledger at the end stamps each action into a JSONL ribbon while a row emerges as a finished object.
The router avoids unnecessary LLM calls, but still hands off the interesting cases to agents that can update the virtual database.

This is the best engineering move in the repository. Not every query deserves the same amount of invention. Routine metadata can come from memory or a fast cache. The ambiguous or state-changing cases go through specialized agents.

// Conceptual shape of the router
switch (classify(sql)) {
  case 'fast-path':
    return answerFromMemory(sql)
  case 'introspection':
    return runExecuteAgent(sql)
  case 'mutation':
    return runTableOrRecordAgent(sql)
}

Why VirtualDbState Is the Real Product

The illusion only works if the server remembers what it claimed five queries ago. That is what VirtualDbState does. It tracks tables, columns, and action history so the next query can be consistent with the last one.

That makes the project feel less like a generator and more like a state machine with a very creative transition function. Once a table exists, later selects can refer to it. Once a row is inserted, later filters can find it.

JSONL Replay Makes the Hallucination Auditable

The system also keeps a JSONL action log. That is a sober design choice in an otherwise playful project. Every mutation can be appended, replayed, and inspected without guessing how the virtual database got into its current state.

This is what turns the project from a demo into a debugging surface. If the hallucination goes wrong, there is a paper trail.

Where It Stops Working

Those limits are not incidental. They define the niche. This is a tool for experiments, not a drop-in replacement for PostgreSQL.

What It Replaces, What It Refuses To Be

Tool typeWhat it gives youWhat it refusesWhere pg-llm-usodb fits
SQL mockPredictable canned answersReal protocol behaviorToo static for agent testing
Text-to-SQL assistantNatural language to SQLA believable database backendIt goes the other direction
Real PostgreSQLDurable data and correctnessSynthetic invention on demandIt imitates the interface, not the guarantees
pg-llm-usodbA database that improvises under loadTruthful storageA protocol-faithful hallucination engine

That last row is the whole story. The project is useful because it stands in the awkward space between fake and real. It is convincing enough to test software, but unstable enough to expose how much of a client’s trust lives in the wire protocol itself.