Skip to content

How I Write Specs for a PostgreSQL Kernel

Yesterday my friend Jiang and I spent hours arguing about whether specs are worth writing. I promised to show you a real project today, so here’s Mimus, which I started yesterday. I want to bring several PostgreSQL variants and extensions together on a common base. The goal is a single kernel that understands both MySQL’s SQL dialect and SQL Server’s T-SQL, can use pg_tde for transparent data encryption, and still lets you install other PostgreSQL extensions as usual.

Fortunately, much of the code already exists. Most of my work is bumping versions, merging patches, and resolving conflicts. But this is a database kernel. If two patches work on their own, do they still work together? Which combinations have I tested, and which ones would I just like to try? When I hand the work over to another agent, it needs somewhere to look that up.

How I organize the workspace

I recently did a clean install on my old M1 Max Mac. That gave me a chance to sort through the context and skills I’d accumulated over the years. I use ChatGPT, Claude Code, and Gemini on that machine, both in their desktop apps and at the command line. Each has its own global rules file. I keep a link to each one in ~/env/dot/.

ln -sfn ~/.codex/AGENTS.md  ~/env/dot/CODEX.md   # Codex (CLI and ChatGPT.app)
ln -sfn ~/.claude/CLAUDE.md ~/env/dot/CLAUDE.md  # Claude Code (CLI and Code tab)
ln -sfn ~/.gemini/GEMINI.md ~/env/dot/GEMINI.md  # Antigravity (app, IDE, CLI)

Those links bring the rules from all three tools’ directories together in one place. In those files I spell out my background, what I want to do, and what matters to me. Anything an agent should remember when it moves to a different project belongs in its global constitution.

Then there’s the project itself. I usually keep Git repositories that serve the same goal in one working directory. A monorepo would work too. For Mimus, I’m merging code from several upstream projects, and each repository has its own history. I kept them separate and added the whole mimus/ directory as a project in ChatGPT, Claude, and Antigravity.

A project constitution and two documentation sites

Here’s the part of the Mimus directory that matters for documentation.

mimus/
├── AGENTS.md
├── docs/
└── spec/

All three agents share the AGENTS.md at the root. It’s where I explain what Mimus is supposed to do and what rules apply to anyone changing it. For spec-driven development, I give the agents one rule. Use spec-anchored development and update the corresponding spec whenever you change the code.

Both docs/ and spec/ are Hugo sites. The first is for users. Its home page shows which protocols the kernel is meant to support and how they fit into PostgreSQL. The second is for me and the agents doing the work. It tracks the problems we still have to solve to deliver on that promise. A small project could easily combine the two sites. For a project the size of Mimus, I prefer to keep them separate.

Building the sites was the easy part. I even had Claude help me write the prompt for it. I just plug in the project name and describe what I want to build. Once I’ve used the same prompt a few times and like how it works, I can turn it into a skill.

What goes on the spec site?

Here’s where Jiang and I agree. Imagine starting every feature with a stack of BRDs, MRDs, PRDs, and SRSs. Then come the user stories, use cases, SADs, RFCs, and ADRs, followed by test plans, runbooks, playbooks, and SOPs. I’d get tired of that too.

I regularly add to just three sections on the Mimus spec site.

  1. Idea is where I work out the requirements. I brainstorm with an agent until we’re clear on what we want to do. If a proposal would benefit from feedback, I can write it up as an RFC. Once we’ve settled the requirements, I put them in a product requirements document (PRD). Both go under Idea. Writing down an idea doesn’t commit me to building it.
  2. Spec is where I spell out the implementation. I take a feature or an iteration from Idea and write down what we’ll do, how we’ll do it, and how we’ll verify it. One file is enough for a small change. A larger spec can have its own directory. This is the section I consult most often. As the code changes, its spec has to keep up.
  3. ADR is where I record why we made a decision. We write an architecture decision record (ADR) when I have to make a judgment call or an agent thinks a choice is worth explaining to whoever takes over. We record what we chose, what we passed up, and our reasoning at the time. Otherwise the next agent is liable to make the same mistake all over again.

The other documents change much less often. The charter sets out the project’s mission, vision, and values. The architecture page explains how the kernel and the extensions relate to one another. If the project needs operations docs, make room for operating manuals, troubleshooting procedures, and test records. For a project starting from scratch, I’d use four sections. I’d put the charter, core rules, and architecture in the AGENTS.md the agents read every session, then add to Idea, Spec, and ADR as the work progresses.

Why leave OrioleDB out of this release?

On yesterday’s spec site, SPEC-012 is titled “Three Generations of OrioleDB Kernel Patches and a PostgreSQL 19 Port Assessment.” Its status is done. It’s easy to read that and assume Mimus already supports OrioleDB. What we finished was the assessment. Scroll down to the decisions and you’ll find ADR-0004, “Leave OrioleDB out of this Mimus release.”

On the Mimus spec site, SPEC-012 marks the port assessment as done. ADR-0004 records the decision to defer OrioleDB for this release.

This is also how an agent reports back to me. I can look up what it worked on, what trade-offs it found, what I chose after hearing the pros and cons, and which new specs followed from that decision. Three months from now, the code alone will tell me only that OrioleDB is missing from the kernel. Those two records will tell me we assessed the port and deliberately put it off.

Honestly, code is cheap these days. What I value more is knowing which questions we asked, which prompts we used, and why we chose one approach over the others. Code gives you a snapshot. It’s hard to reconstruct how you got there from that snapshot alone.

John Gall observed that a complex system that works always evolves from a simple system that works. Design a complex system from scratch and chances are it won’t work on the first try. With Mimus, I want to keep a record of that evolution. When someone asks, “Why did we change it that way?” there’ll be somewhere to look, even if it’s me asking three months from now.