Database administration

info — Database metadata

Display metadata and statistics of a database.

./blunderdb info --db <path> [--format <format>] [--estimate]

Options:

  • --db — Database (required).

  • --format — Output format: text or json (default: text).

  • --estimate — Answers at once on a very large database: beyond 200,000 rows a number is an estimate (an upper bound), listed in approximate in JSON and prefixed with “≈” in text, and blunders are given only when their cached count still holds (otherwise no blunder_count). By default every row is counted; the blunder count is cached in the database and recounted after any write that can change it (import, analysis, deletion, threshold change).

Examples:

./blunderdb info --db base.db

# Database Information
# ==================================================
# Path: /home/jean/bg/base.db
#
# Metadata:
#   Version: 2.31.0
#   User: Jean
#   Description: Matchs de tournoi 2025
#   Date of Creation: 2026-09-06 02:43:51
#
# Statistics:
#   Positions: 3859
#   Analyses: 3855
#   Matches: 11
#   Games: 61
#   Moves: 3766
#   Blunders: 142
#
# Thresholds (millipoints):
#   Error: 50
#   Blunder: 100

--format json adds the file’s origin — issuance carries the watermark if there is one, and this machine’s issuer identity:

./blunderdb info --db base.db --format json
{
  "issuance": {
    "watermarked": false,
    "issuerFingerprint": "1186-57FA-060C-9378",
    "issuerName": "unger"
  },
  "library_settings": {
    "errorThresholdMP": 50,
    "blunderThresholdMP": 100
  },
  "metadata": {
    "database_version": "2.31.0",
    "dateOfCreation": "2026-09-06 02:43:51",
    "description": "Matchs de tournoi 2025",
    "user": "Jean"
  },
  "path": "/home/jean/bg/base.db",
  "stats": {
    "analysis_count": 3855,
    "blunder_count": 142,
    "game_count": 61,
    "match_count": 11,
    "move_count": 3766,
    "position_count": 3859
  }
}

edit — Edit metadata

Edit the user name, the description or the thresholds of a database.

./blunderdb edit --db <path> [options]

Options:

  • --db — Database (required).

  • --user — New user name.

  • --description — New description.

  • --clear-user — Clear user name.

  • --clear-description — Clear description.

  • --error-threshold — Error threshold, in millipoints: a decision costing at least this much is an error.

  • --blunder-threshold — Blunder threshold, in millipoints: an error costing at least this much is a blunder.

  • --format — Output format: text (default) or json ({"changes": [...]}).

At least one edit option is required.

Examples:

./blunderdb edit --db base.db --user "Marie" --description "Ma collection"
./blunderdb edit --db base.db --clear-description
./blunderdb edit --db base.db --error-threshold 20 --blunder-threshold 80

verify — Verify integrity

Verify database integrity and optionally compare a match against its source file.

./blunderdb verify --db <path> [--match <id>] [--mat <file.mat>]

Options:

  • --db — Database (required).

  • --match — Match ID to verify.

  • --mat — MAT file to compare against (used with --match).

  • --format — Output format: text (default) or json (statistics, orphans, schema drift, and the match check if any).

Without --match, the command displays general database statistics. With --match, it verifies the match data and can compare it against the original source file.

Every run also checks referential integrity: it counts orphaned rows — games without a match, moves without a game, move analyses without a move, analyses without a position, review-journal entries without a deck or without a position, training questions without a session — and prints a WARNING line with the total when any exist. A healthy database answers Orphaned rows: none. Orphans can linger in a database written by a version that did not enforce foreign keys on every connection, or before the review journal had its own; they belong to no match and to no deck, and only take up space. The command still exits with code 0.

Every run also compares the schema against the reference DDL and lists the tables, columns and indexes the database lacks. Opening a database adds what is missing when it can and only logs what it cannot add (typically a UNIQUE index that duplicate rows keep it from rebuilding): this is where that gap becomes visible, and a query naming one of those elements fails until the cause is fixed. A healthy database answers Schema: matches the reference DDL. Like orphans, schema drift is a finding, not a failure: the exit code stays 0.

Every run finally checks the rules the current DDL states but SQLite cannot add to a table that already exists: the range CHECK constraints (dice between 0 and 6, non-negative cube and pip counts, 0 to 15 checkers off, review ratings between 1 and 4), the Zobrist hash a row should never be without, and one analysis per position. A database created since schema version 2.18.0 enforces them; an older one can still hold rows a new database would refuse, and those are what is counted here, rule by rule. A healthy database reports Constraints: every row satisfies the current DDL. One more finding: nothing is repaired and the exit code stays 0.

Every run finally recomputes the two denormalised counters, match.game_count and game.move_count, from the rows they claim to count, and reports how many disagree and by how much at worst. Both are written once, at import, from what the source file held, and are what the match list and the game view display: a small gap is usually an import that skipped what it could not convert. Nothing is rewritten — replacing the counter with what was stored would erase the very discrepancy worth looking at. A healthy database reports Counters: game_count and move_count agree with the rows.

Examples:

./blunderdb verify --db base.db
./blunderdb verify --db base.db --match 1
./blunderdb verify --db base.db --match 1 --mat original.mat

Using it as a guard. The exit code is 0 whatever the command finds: it is --format json that carries the verdict, and a script must read the counters itself.

{
  "stats": {
    "analysis_count": 3855,
    "blunder_count": 142,
    "game_count": 61,
    "match_count": 11,
    "move_count": 3766,
    "position_count": 3859
  },
  "orphans": {
    "games_without_match": 0,
    "moves_without_game": 0,
    "move_analyses_without_move": 0,
    "analyses_without_position": 0,
    "reviews_without_deck": 0,
    "reviews_without_position": 0,
    "training_items_without_session": 0
  },
  "orphan_total": 0,
  "schema_drift": {
    "missing_tables": null,
    "missing_columns": null,
    "missing_indexes": null
  },
  "schema_drift_count": 0,
  "constraint_violations": [
    {"name": "position.zobrist_hash NOT NULL", "count": 0},
    {"name": "position.dice_1 BETWEEN 0 AND 6", "count": 0}
  ],
  "constraint_violation_total": 0,
  "counter_drift": {
    "matches_with_wrong_game_count": 0,
    "games_with_wrong_move_count": 53,
    "worst_game_count_gap": 0,
    "worst_move_count_gap": 2
  },
  "counter_drift_total": 53
}

Three fields are worth an alarm: orphan_total, schema_drift_count and constraint_violation_total. When non-zero, they describe a database that needs repairing.

./blunderdb verify --db base.db --format json \
  | jq -e '.orphan_total == 0 and .schema_drift_count == 0 and .constraint_violation_total == 0'

counter_drift_total is not one of them, and the example above shows why: the database that produced it had just been imported and already shows 53 games whose move counter differs from what the rows contain. These counters come from the source file, not from the database; a gap tells the story of the import, it does not signal corruption. Look at it, do not use it as a threshold.

vacuum — Compacting the database

Reclaims the disk space left behind by deletions (matches, tournaments, purges): SQLite never shrinks the file by itself when data is deleted, it has to be asked explicitly. This is the only way to trigger a compaction — it never happens automatically when a database is opened, because its cost is unpredictable on a large one.

./blunderdb vacuum --db <path>

Options:

  • --db — Database (required).

  • --format — Output format: text (default) or json ({"size_before", "size_after", "reclaimed"}, in bytes).

The command starts with a wal_checkpoint(TRUNCATE) so that the size reported before compaction is honest, checks that about the file’s size is left as free space next to it, writes the compacted database into a copy (VACUUM INTO) that then replaces the file, and then runs an ANALYZE to refresh the statistics the query planner uses. If another program has the database open, the file is not replaced: the command compacts in place (VACUUM), which needs about twice the file’s size in free space. If disk space is short, the command refuses to start with an explicit message rather than risk an interrupted compaction.

Before compaction, every analysis still stored as JSON by an earlier version is rewritten in the compact binary format (see reencode).

Example:

./blunderdb vacuum --db base.db

# Compacting database...
#   Before: 128.4 MiB
#   After:  41.2 MiB
#   Reclaimed: 87.2 MiB

met — The library match equity table

Lists, imports or selects the match equity table (MET) with which gammonNet values the database’s match scores: Kazaross-XG2, built in and the default, or an explicit table in GNUbg .xml format. Each computed analysis records its table; a match-score analysis computed with a table other than the current one is left out of the statistics. Changing the table rewrites no analysis.

./blunderdb met --db <path> [--import <fichier.xml> [--current] | --use <id>]

Options:

  • --db — Database (required).

  • --import — Imports a GNUbg .xml table. A table that is already present, or identical to Kazaross-XG2, is not added a second time.

  • --current — With --import: makes the imported table current.

  • --use — Makes the table with the given identifier current; 0 goes back to Kazaross-XG2.

  • --format — Output format: text (default) or json.

The command then prints the database’s tables, the current one marked with a *. The daemon exposes the same operations on the met.list, met.import, met.setCurrent and met.ofAnalysis routes, limited to the caller’s tenant.

Example:

./blunderdb met --db base.db --import Rockwell-Kazaross.xml --current

#     0  Kazaross-XG2
# *   1  Rockwell/Kazaross 25 point MET

reencode — Rewrite analyses in the compact format

Analyses are stored in a compact binary format, about half the size of the compressed JSON of earlier versions and several times faster to read back. A database created before this format remains readable as is: its older analyses are converted when they are rewritten (an import that enriches them, a vacuum). reencode converts them all, without compacting the file: useful when the disk has no room for the compacted copy that a vacuum writes, or on a PostgreSQL server, which has no vacuum.

./blunderdb reencode --db <path>

Options:

  • --db — Database (required).

  • --format — Output format: text (default) or json ({"rewritten"}, the number of analyses rewritten).

The conversion proceeds in batches of 2,000 analyses, each in its own transaction. If interrupted, it resumes at the next run where it stopped: analyses already converted are skipped without being read again. An unreadable analysis is left as it is and reported in the log. It never starts by itself. The daemon exposes the same operation on the maintenance.reencode route, limited to the caller’s tenant.

Example:

./blunderdb reencode --db base.db

#   Analyses rewritten: 15623468

maintenance — The health of the database

One line per maintenance operation: what it counts, its action and its latest run. Nothing starts by itself: neither when the database is opened, nor when the status is read.

./blunderdb maintenance status --db <path>
./blunderdb maintenance count <opération> --db <path>
./blunderdb maintenance ids <opération> --db <path>
./blunderdb maintenance run <opération> --db <path>

Subcommands:

  • status — All operations, with the free counters and the latest run of each. An expensive counter shows (count on demand): count computes it.

  • count — Computes an operation’s counter, whatever its cost.

  • ids — Lists the identifiers the operation counts (positions or matches); their number is the answer of count.

  • run — Runs an operation’s action and records it as its latest run (completed, cancelled or failed). Ctrl-C stops it between two batches.

Operations:

Operation

Counter

Action

analysis.missing

Positions with no analysis at all, on demand.

The analyze command.

stats.matches

Matches without per-match statistics.

Computes them.

analysis.columns

—

Recomputes the columns derived from the analyses.

analysis.legacy

—

Rewrites analyses in the compact format (reencode).

trash

Trash entries.

The trash command.

vacuum

Free bytes in the file (SQLite).

The vacuum command.

Options:

  • --db — Database (required).

  • --format — Output format: text (default) or json.

The latest run is stored in the database, with its settings; an export does not carry it. Only one operation runs at a time. The daemon exposes the same sub-commands on the routes maintenance.status, maintenance.count, maintenance.ids, maintenance.run (as an NDJSON stream, cancellable through maintenance.cancel), restricted to the caller’s tenant; an operation requested while a gammonNet analysis or a rollout is running for that tenant is refused.

Example:

./blunderdb maintenance run stats.matches --db base.db

#   stats.matches: done, 1204 changed

players — A player’s spellings

The same person sometimes signs in several ways from one file to another (“Doe J.”, “John Doe”). An alias says that a name is another spelling of a canonical name. Matches already in the database keep the names their files write; the statistics, the Players table and the pl"…" search read all the spellings as a single person, and every later import records the canonical name. The player merge of the matches window creates the same aliases.

./blunderdb players alias <add|list|remove|suggest> --db <chemin> [arguments]

Actions:

  • add ALIAS CANONIQUE — ALIAS becomes a spelling of CANONIQUE. A canonical name that is itself an alias is followed to its own canonical name, and the aliases that pointed to ALIAS move to CANONIQUE: a single level, never a chain.

  • list [--format text|json] — The aliases, sorted by canonical name.

  • remove ALIAS — Forgets an alias; exits with an error if it was not one.

  • suggest [--format text|json] — Proposes the names that differ only by case, accents, punctuation or word order, with the most frequent spelling as canonical. Nothing is recorded: each suggestion is written as the add command that would apply it.

Fingerprints. A match’s fingerprints (match_hash, canonical_hash) keep the names of the file: the alias applies after them, to the recorded names only. A file imported before its alias existed is therefore still recognised at the next import. A match imported under another spelling, whose dice are those of a match in the database and whose names differ only by known aliases, is recognised as the same match: its analyses enrich the existing one, no second match is created.

./blunderdb players alias add --db base.db "Doe J." "John Doe"
./blunderdb players alias suggest --db base.db

players merge — The player merge of the matches window, from the same code as the daemon’s matches.mergePlayers route: each name becomes a spelling of the canonical name, like as many players alias add.

./blunderdb players merge --db <chemin> --into <CANONIQUE> <NOM> [<NOM>...]

players swap — The swap of a match’s two players, which the file had named in the wrong order (route matches.swapPlayers). No position and no analysis changes: each player keeps their statistics, under the other seat. The swap is refused while a transcription draft is open on the match, and for a match played in blunderDB.

./blunderdb players swap --db <chemin> <ID_MATCH>

players main — The main player of the matches window (routes players.main.*). Without a name, shows the main player; with a name, designates that player and, in a single transaction, swaps every match where he or she or one of the aliases is player 2; every later import places that player as player 1. --dry-run shows the matches to swap without changing anything; --clear removes the main player without swapping anything back. A match with an open transcription draft, or played in blunderDB, is left as is and listed separately.

./blunderdb players main --db <chemin> [--dry-run] [<NOM>]
./blunderdb players main --db <chemin> --clear

players matches — The identifiers of a player’s matches, on either side of the board and under all of his or her aliases (route players.matchIds).

./blunderdb players matches --db <chemin> <NOM>
./blunderdb players merge --db base.db --into "John Doe" "Doe J." "J. Doe"
./blunderdb players swap --db base.db 42
./blunderdb players main --db base.db --dry-run "John Doe"

events — An event’s spellings

The same actions as players alias, for event names (the Event field of a file). On import, a match whose event is an alias is filed in the tournament of the canonical name.

./blunderdb events alias add --db base.db "Open 2025" "Open d'automne 2025"
./blunderdb events alias list --db base.db

repair — Recompute what is derived

Recomputes what the database derives from what it stores: the scalar columns of every analysis from the analysis itself, of which they are only a projection; each position’s phase and game type from its board; and the Crawford sentinel of every score from the match the position came from, or from the XGID it came in with. The analyses are not touched: what is redone are the values that had been derived from them.

A database that received analyses by importing another database (import --type database, including through a watched synchronisation folder) with a version earlier than this one keeps those analyses without their columns, or with those of the analysis they replaced: their blunders are not counted and their forced moves count as decisions. repair compares these columns with what the stored analysis yields and redoes those that differ; the same content then counts as if it had come through transfer.

./blunderdb repair --db <path>

Options:

  • --db — Database (required).

  • --format — Output format: text (default) or json — one counter per pass: repaired (analysis columns), phases (reclassified positions) and crawford (rehashed positions), and signatures_unverified (signed comments that a rehash leaves unverified: a signature covers the identity of the position). Each gives the number of rows actually changed. With --stats, match_stats (matches recomputed) is added.

  • --stats — Also recomputes the per-match statistics from scratch.

  • --duplicates — Runs none of the passes: lists the pairs of matches that the dice say are identical, without merging anything (see below).

The per-match statistics are, for each player of each match, their decisions, cumulative error, PR, blunders, luck and the dominant provenance of their analyses; the statistics read them instead of walking through every decision again. They are written with the match at import and cleared by every change that alters them (match deleted, players swapped, analysis of one of its positions modified, blunder threshold moved); the next read recomputes what is missing. A database migrated from an earlier version computes them once, on first opening. --stats redoes them all: the remedy should this bookkeeping ever go wrong.

Probable duplicates. repair --duplicates compares matches by their dice, never by their names. Two cases are reported: the same length, the same initial score and the same dice in each game under other player names, and a match whose dice extend those of another — a match truncated then completed. Under a pair with the same dice, the text output gives the players alias add commands that would make the two matches name the same players: a single reading when a name is common to both (the other name can only be the other player), otherwise two — seat for seat, then crossed — numbered, of which only one is to be run. The spelling of the most recent match becomes the alias, that of the oldest the canonical name. --format json returns {"suspects": [...]}, each pair with kind (same_dice or longer), matchId, otherId, players, otherPlayers and, for a pair with the same dice, pairings: the list of readings, each with its aliases (alias, canonical). A match imported before the dice fingerprint existed receives it along the way; this is the only write of this mode.

Useful after a correction to the way an imported analysis is read. It has already happened twice. The XG importer writes a “no double” two different ways, and the second was understood as a real double — the column then carried the error of a double that never took place. And an analysis blunderDB had computed itself did not know which move had been played, so a match imported without an analysis kept a zero error everywhere and a PR of 0.00; the column is recomputed from the match’s moves. Correcting the reading changes nothing in the rows already written; this command redoes them.

The Crawford pass, for its part, touches the positions themselves. A score of 1 means “one point to go, and this game IS the Crawford game”; 0 means “one point to go, Crawford behind us”. Until the importers wrote that distinction, every post-Crawford position was recorded as a Crawford one, and therefore read with a dead cube — where the trailer in fact doubles at the first opportunity. Correcting the score changes the position’s hash: the row is therefore rehashed, and merged with its correct twin if the database already holds one — the analysis, the comments, the collections, the Anki cards and their review journal, the match moves and the trash entries that name it follow the surviving row. A position no match points at is corrected only on the word of the XGID it brought from another program (XG, BGBlitz…): when that XGID’s Crawford field says the game is not the Crawford one, and the XGID does describe this position. The other way round, a position without a match stored at 0 on both sides moves to 1 when the XGID it brought is that of a 1-point match and describes it: the only game of a 1-point match starts one point from the goal, so it is the Crawford game, as the importers write it. The DMP after the Crawford game of a longer match stays at 0: its XGID gives the length of that match. An XGID blunderDB rewrote itself only repeats the stored score and proves nothing. Any other position without a match is left as it is: nothing contradicts what its score announces.

Nothing triggers it automatically, and that is deliberate: rewriting everyone’s analysis columns, or rehashing positions, on the mere act of opening a database is not something a tool should do behind its user’s back.

Example:

./blunderdb repair --db base.db

# 42 analyses repaired.
# 7 positions reclassified.
# 3 positions rehashed onto the right Crawford sentinel.

delete — Delete data

Delete a match and all associated data (games, moves, analyses).

./blunderdb delete --db <path> --type match --id <id> [--confirm]

Options:

  • --db — Database (required).

  • --type — Delete type: match (required).

  • --id — ID of the item to delete (required).

  • --confirm — Delete without asking for confirmation.

  • --format — Output format: text (default) or json ({"match_id": N, "deleted": true}).

Examples:

# Confirmation interactive, puis sans confirmation (scripts)
./blunderdb delete --db base.db --type match --id 1
./blunderdb delete --db base.db --type match --id 1 --confirm

healthcheck — Probing a daemon

Asks a running serve daemon (see Headless mode (server)) whether it is ready: one GET /readyz request, exit code 0 when the daemon answers 200 (storage reachable, schema at the expected version), 1 otherwise — storage unreachable, stale schema, or nothing listening at the address. No database file is opened.

./blunderdb healthcheck [--addr host:port] [--timeout 2s]

Options:

  • --addr — Address the daemon listens on (default BLUNDERDB_ADDR, else :8080). An address without a host (:8080) or with a wildcard host (0.0.0.0, [::]) is probed on the loopback interface.

  • --timeout — Give up after this long (2s by default).

This is the command the container image’s HEALTHCHECK runs (a distroless image, without curl); the serve binary built from cmd/serve understands it too. It works just as well from a script or a systemd unit.

Example:

./blunderdb serve --db base.db --addr 127.0.0.1:8080 &
./blunderdb healthcheck --addr 127.0.0.1:8080 && echo "démon disponible"

# ready

On failure the reason is printed, which docker inspect reproduces for an unhealthy container:

Error: healthcheck: http://127.0.0.1:8080/readyz answered 503 Service Unavailable (version_mismatch)

mcp — Offer the database to an AI assistant

Serves the database tools to an AI assistant through the Model Context Protocol, over standard input and output: the assistant launches the command. The tools search positions in the command-bar grammar, read a position and its analysis, explain an error, compute a player’s statistics, list matches, tournaments and collections, and ask a quiz question. They only read, except with --write. The full list and the daemon’s HTTP equivalent: Tools for an AI assistant (MCP).

./blunderdb mcp --db base.db [--write]

Options:

  • --db — Database file (required).

  • --write — Also offers the tools that write: save a position, comment it, create and fill a collection. Nothing is deleted.

Like call, the command migrates an older database’s schema when it opens it, even without --write.

Example: declare the database to Claude Code.

claude mcp add blunderdb -- blunderdb mcp --db /chemin/vers/base.db

completion — Shell completion

Prints a shell completion script for the subcommand names to standard output. The command list embedded in every script is generated from the same table blunderdb help and main.go’s dispatch read (handlers()): a new subcommand is therefore offered by completion as soon as it is wired in, with nothing to keep up to date by hand.

./blunderdb completion <bash|zsh|fish>

Examples:

# bash
source <(blunderdb completion bash)
blunderdb completion bash | sudo tee /etc/bash_completion.d/blunderdb > /dev/null

# zsh : un répertoire déjà sur $fpath
blunderdb completion zsh > "${fpath[1]}/_blunderdb"

# fish
blunderdb completion fish | source

Packages install this automatically: the .deb/.rpm (nfpm) and the AUR package generate the three scripts from the packaged binary at build time, and the Homebrew cask runs blunderdb completion <shell> once at install time via generate_completions_from_executable. Nothing is committed to the repository, so completion can never drift from the subcommand table.

version — Show the version

Prints blunderDB’s version and the database schema version this binary writes; it is the first thing to attach to a bug report.

./blunderdb version
# blunderDB version 0.36.0 (database schema 2.31.0)