Command line
DB Desk is a window, but everything under the window is a library: the engine modules, the
encrypted vault, the read-only guard, the production approval flow. The dbdesk command calls the
same functions the window calls, so a rule that holds in the app holds here — there is one
implementation of "run this SQL safely", not two that drift apart.
Use it for the things a window is bad at: a cron job that exports a table, a one-off check on a server with no display, a script that asks three databases the same question.
Install
A packaged install ships the CLI inside the sidecar binary:
dbdesk-server cli connections # or the `dbdesk` symlink the installer adds
From a source checkout:
bin/dbdesk connections
Both read the same connections.json and the same encrypted secrets as the app, so a connection
you added in the window is already there — and no password is ever passed as an argument, because
that would put it in your shell history.
Commands
| Command | What it does |
|---|---|
dbdesk connections |
List saved connections: name, engine, target, and whether writes are allowed |
dbdesk test [NAME …] |
Open each connection and print the server version |
dbdesk tables NAME |
Schemas, tables and views |
dbdesk columns NAME TABLE |
Column names, types, nullability, defaults |
dbdesk rows NAME TABLE |
One page of rows (--limit, --offset) |
dbdesk query NAME "SQL" |
Run SQL; -- or a missing argument reads SQL from stdin |
dbdesk export NAME --table T --out f.csv |
Write CSV (or JSON by extension), or --sql instead of --table |
dbdesk serve [--port N] |
The local server and web UI |
dbdesk mcp |
MCP over stdin/stdout |
dbdesk version |
Version and data directory |
A connection can be named by its id, its exact name, or an unambiguous prefix: dbdesk tables
wor finds work-prod if it is the only one that starts that way, and refuses to guess otherwise.
--schema is optional when the connection has exactly one schema (SQLite always has main); with
several schemas it asks rather than picking one for you.
Output
--format table (the default) is the aligned human view; --format json prints columns, rows and
metadata; --format csv and --format tsv are for other programs. --json is a synonym for
--format json, and both work before or after the subcommand.
dbdesk query prod "select count(*) from orders" --json | jq '.rows[0][0]'
dbdesk rows prod orders --limit 5000 --format csv > orders.csv
dbdesk export prod --sql "select * from orders where created_at > now() - interval '1 day'" \
--out yesterday.json
Exit codes are for scripts: 0 success, 1 the database or the guard said no, 2 a usage mistake
(unknown connection, missing argument). Errors go to stderr as dbdesk: <sentence>; set
DBDESK_DEBUG=1 to see the traceback instead.
What it will refuse
The CLI is not a way around the app's rules — that is the point of reusing the route functions:
- a connection marked read-only refuses a write, exactly as in the window:
dbdesk: read-only connection: only SELECT/SHOW/EXPLAIN statements are allowed, exit1; - a production connection still needs its single-use approval, which cannot be granted from a shell — approve it in the app, then re-run;
- the write audit log records the statement the same way, with
via: cliin the context, so a cron job does not become an invisible path to the database.
If a script needs to write to a read-only connection, the fix is a second connection with writes enabled, not a flag on this command.
Examples
# is anything down this morning?
for name in $(dbdesk connections --format csv | tail -n +2 | cut -d, -f1); do
dbdesk test "$name" || echo "!! $name"
done
# nightly export of the three tables the report needs
dbdesk export prod --table orders --out /backup/orders.csv
dbdesk export prod --table clients --out /backup/clients.csv
# what does this query plan look like on the replica?
dbdesk query replica "explain analyze select * from orders where status = 'paid'"
Limits worth knowing
- One page of rows per call, capped at
MAX_ROWS(2000), because the same cap protects the app from a query that returns a million rows. Use--sqlwith a narrowerwhereclause rather than a bigger limit. --limitapplies to rows printed, not to work the server does:select * from bigstill scans.- The CLI does not open SSH tunnels itself for
mcporhttpconnections beyond what the app already does; a tunnel-backed database connection works because the same code path builds it. - It never prompts. Anything interactive — approving a production write, unlocking a vault with a passphrase — belongs in the app.