Repository navigation
pgman v0.1.0
First public release. pgman is a terminal UI for PostgreSQL in the k9s
mould, built for teams running Java services on AWS. Point it at a
database — or let it find the connection in your Spring
application*.yml, IntelliJ data sources, or a committed
.pgman/pgman.toml — and you get a query editor with completion and
history, a schema browser, EXPLAIN trees, slow-query and session panels,
and a results grid you can filter, sort, diff and export. What nothing
else does: paste a Hibernate log, a Postgres server log, or a JDBC
statement with its parameters, and pgman reconstructs the runnable SQL,
clusters N+1 loops, and runs it — no application changes, works offline.
Connections are read-only by default, every statement is classified and
guarded before it reaches the server, and anything discovered in a
working tree is treated as untrusted until you confirm it. A live JDBC
tap (OpenTelemetry today) shows what the application is actually
sending. Install with brew install tombaldwin/tap/pgman, cargo install pgman --locked, or a tarball from the releases page; pgman --demo
runs the whole thing against synthetic data. Pre-1.0: expect rough edges
and breaking changes.
What's in it
- Connect — auto-discovery from Spring
application*.yml/
.properties(with profile overlays and${VAR}/${VAR:default}
from the environment), IntelliJ.idea/dataSources.xml, and a
committed.pgman/pgman.toml; a picker that shows host,sslmode,
tunnel and credential provenance before anything connects; a start
card on connect with databases, sizes and the keys that matter. - Logs and pasted code → runnable SQL — Hibernate logs (with
bind-parameter trace logging), Postgres/RDS server logs, and pasted
JDBC statement + parameters; N+1 detection; a pasted log is recognised
in the editor;pgman --log PATHopens straight into the picks. - Editor — Enter runs a statement that ends in
;(psql's rule),
Alt-Enter runs regardless; opens five lines tall and grows with its
content; syntax highlighting, identifier and keyword completion,
auto-indent, Ctrl-F formatting (built-in,pg_formatwhen
installed; never on run or paste), history, undo/redo, saved queries
with:paramprompts,$EDITOR,\watch, DBUnit fixture apply and
capture. - Safety — read-only by default,
statement_timeout, per-database
guards (block / confirm / allow) on every statement, DML left in an
open transaction until you commit or roll it back,EXPLAIN ANALYZE
always rolled back, and a
project's[safety]block can only tighten yours. A read-only
session also refuses the server-control functions Postgres's own
read-only mode lets through (pg_promote,pg_wal_replay_pause,
replication slots,pg_stat_reset…). - DBA panels — schema browser, schema-lint wizard, EXPLAIN tree,
slow queries, sessions and locks, result diff,\l,\x,\c,\i,
the\dfamily,\timing. - MCP server —
pgman mcp servegives Claude Code (or any MCP
client) tools:query,sessions_locks(a pre-flight before a schema
change),pending_patches,connections,environmentsanddoctor,
with more below. Every session is read-only whateversafety.toml
says, exceptapply_patches(see Applying patches below);
personal connections can tunnel and read their password from AWS
Secrets Manager; aprimaryconnection serves only the lock check. - Environments overview —
Elists every database in each
environment, replicas under their primary, from RDS (via theaws
CLI) or hand-listed connections, without connecting to any of them.
Enterconnects to a row: replicas read-only, the password read from
AWS Secrets Manager at that moment, through the environment's ssh
tunnel. pgman env discoverproposes environments from an AWS account:
one per RDS primary with its replicas, the secret matching each
database by name, the bastion in its VPC. It reads names only, never a
secret's value;--saveappends toenvironments.toml. In the
overview,ddoes the same with a preview of what each save appends.
Over MCP,environments_discoverandenvironments_savedo it for an
agent (save refused under--read-only).- ebman's look — rounded panels with
[ ◆ name ◆ ]titles
(a plainnameunder Powerline fonts, as in ebman), ebman's two-box
header on terminals 24 rows or taller (server, database, user,
session, and where the connection came from, beside the current view
and the global keys), coloured key hints in the footer, and uppercase
panel column headers. The drawing vocabulary now lives in
tb-tui-common, shared with ebman. --batch --discoveredaccepts a checkout that declares one
database twice (identical URL and credentials) as a single candidate.- MCP tunnels stay open between calls to the same database (5
minutes idle), so a run ofquerycalls pays the ssh handshake once;
each call still gets a fresh read-only session. - Partitioned tables fold in the schema browser: one
N partitions
row under the table instead of a screenful of partitions. A database
with one schema opens with it expanded. - Slow queries says why it's empty: without
pg_stat_statements
the panel stays open with how to install it, instead of flashing
shut. - Esc from the results goes back to the environments overview.
- Environments are home. pgman starts on the overview (with
environments configured and no--dsn), full screen, on the row you
used last. Replicas sit under each database. Probing environments
showSCHEMA,LAG,SESSIONSandSIZEcolumns. - Connecting to RDS works for ordinary users. The start card sized
every database on the server, and RDS'srdsadminrefuses that to
anyone but RDS, so the whole connection failed. Only databases you
can connect to are sized now, and a failed list never fails the
connection. - A
dockerenvironment source — local Postgres containers, from
docker ps, reached on their published port. Environments can name
password_envfor databases without a secret. (Earlier docs said
~/.pgpassandPGPASSWORDapplied; pgman never read them for
environments.) - Probes —
probe = trueon an environment adds each database's
patch level, pending patches and replica lag to the overview. It reads
through replicas (a primary with a replica isn't touched), uses one
ssh per bastion, and every connection is read-only. - More at a glance in the overview. RDS rows show the minor and
major upgrades available (↑16.15 · 18.6). Without aversion_table,
a probe recognises Flyway, Liquibase, Prisma, sqlx, Django, Alembic,
and Rails / golang-migrate (their sharedschema_migrations) by their
own tables (and counts pending Flyway files
frommigrations_dir).SESSIONSadds blocked sessions and
transactions open over 5 minutes. A replica's detail line sketches its
recent lag.vshows schema drift: each database's version by
environment. - Recent errors from RDS logs —
lon a server in the overview,
environment_logsover MCP: ERROR, FATAL and PANIC lines from the
newest log files, grouped with a count.STATEMENTandDETAILlines
are left out, since they can carry row data. - Applying patches —
Pin the overview,apply_patchesover MCP.
A read-only plan lists the pending patches, each checked against
safety.toml; after you confirm (a protected environment —prodin
its name, orprotected = true— by typing its name; over MCP through
elicitation), each runs in its own transaction with a 5 s
lock_timeout, stopping at the first failure; the result says which
version the database records afterwards. A pending file numbered
below the recorded version is left out and named, not run out of
order. A patch that can't run in a transaction (VACUUM,
CONCURRENTLY, …) is refused up front; in the TUI,oplans it to
run outside one, statement by statement and with no statement
timeout, behind a typed confirm. Esc twice cancels a running patch,
between statements too: the patch rolls back. The plan names the
risky statements (TRUNCATE, aDELETEwithoutWHERE…) its one
confirmation answers; the timeouts are set again before every
statement, so aDOblock can't lift them for the rest of the patch;
a project's[safety]block applies here as everywhere else.
Tab in the plan (modeover MCP) runs a dry run instead — every
patch in one transaction, rolled back, with the same locks as the
real run — or applies the patches to a copy of the database made
on the same server, dropped afterwards.
Never on a replica, and only on a databasesafety.tomllets write. - Safer and more honest, from a four-reviewer robustness pass. A
unicode-escaped name (U&"pg_\0072ead_file") no longer slips past the
safety classifier; MCPqueryresults are capped at 16 KiB a value
and 1 MiB in all; a DSN with two differentsslmodes is refused;
connects give up after 10 s;:connecttakes a URL and never echoes
its password;:readonlyapplies to the live session, so the header
tells the truth.--batchsays when a CSV/TSV export stopped at 1000
rows (exit 3). A caught-up replica of a quiet primary shows no lag.
Hibernate'sshow_sqlconsole lines reconstruct. Find no longer eats
n.ctrl-lworks from the start card.--demo's slow queries,
sessions and wizard work. The help fits small terminals. - The rest of that pass. Plain keys for the F-keys a Mac keyboard
hides behindfn:!opens the error detail (:error,:notify,
:tapspell F2–F4), and the footer names the key that works where
you are.ctrl-coutside the editor andctrl-wover a tab holding
SQL take a second press; aWATCHbadge shows while\watchruns;
a cancel readscancelled, not as the server's error. A later
success takes a stale error off the footer, and the confirm modal
keeps itsy/nkeys.rin the schema browser reloads the schema
(tables other sessions made), and an empty cache on a live connection
reloads by itself;\don a name nothing matches says so. Esc after
Tab gives back what you typed, and Enter runs a finished statement
under a popup nobody picked from. Bracketed IPv6 hosts parse
(postgres://u@[::1]:5433/db);\irefuses files over 8 MB and
anything that isn't a regular file;--log -reads a piped log and
takes keys from the terminal;--demohonours--log.
Environments: Aurora readers sit under their writer; docker finds
postgis and registry-prefixed images, IPv6-only and ranged ports; a
dirty golang-migrate version shows as failed; a text id in a version
table shows instead of an error; drift compares Liquibase, Django and
Alembic versions as names;migrations_dirtakes Flywaylocations,
recursively, Java and Kotlin migrations included. Long lines in the
patch and log views wrap instead of being cut, the detail line cuts
an endpoint at a dot, and the pickers sit centred. - The backlog pass.
\df [pattern]lists functions with psql's
patterns. In the schema browser, tables list their indexes,p
previews five rows anddcopies theCREATEstatement rebuilt from
the catalog. LINT107 flags a serial or identity column nothing keeps
unique. Right afterJOIN … ON, completion offers the foreign-key
predicate.pgman query 'SQL' [--json]runs one statement without
the TUI.sslmode=verify-cachecks the certificate chain but not the
hostname, as libpq does. Safety: aWHEREinside a subquery no
longer qualifies anUPDATE/DELETE, and a non-ASCII dollar-quote
tag is read as Postgres reads it. TheT/Lpanels show numeric,
date, interval and array values instead of?. A long error wraps
onto up to three footer rows; the connection-failure card wraps its
paths whole so they can be copied;--demoopens with the tap quiet
and its burst arrives two seconds in. The update check caps a
response while reading it;--upgraderefuses rather than running
from the temp directory;--batchrepairs pgman's directories to
owner-only as the TUI does. schema_lintover MCP — the schema wizard's findings (missing
primary keys, unindexed foreign keys, unused indexes, bloat, …) for an
agent to work through.- A
:command bar —:about,:help,:update,:readonly,
:connect, and every\command;?opens help from any mode. - Layout you control —
zzooms the results andZthe editor to
the whole screen and back;+-0size the editor; a tab bar
that is always there, labelled by each tab's query, switched with
][and the digits,ctrl-t/ctrl-wto open and close, and
ctrl-]from inside the editor. Every one of these is a key a Mac
terminal actually delivers; the Alt chords remain as secondaries. - Row detail steps rows —
J/K(or PageDown / PageUp) move to
the next and previous row without leaving the view, keeping the
field you had highlighted, and the grid selection follows. - JDBC tap — live app-side query observability via OpenTelemetry
(TCP and UDP listeners for the forthcomingpgman-tapJAR), hotspots,
per-caller and per-pool rollups, transaction view, baseline diff,
live N+1 detection, Markdown / HTML report export. - Batch mode —
--batch --sql … --format csv|tsv|json|expanded
for scripts and CI, with typed JSON and the same guards;--yes
confirms guarded writes and never lifts read-only. - Install and upgrade — Homebrew, crates.io, or a release tarball
for four targets with build provenance;pgman --upgradeknows
which channel installed it; an update check at most every six hours
that never delays the first frame (--no-update-check). --demo— the whole tool against synthetic data, no database,
answering queries through the real guards. Its database isledger,
the billing database of a made-up subscriptions product: 26 relations
acrosspublicandreporting(partitioned usage events, views,
identity keys, partial indexes), answers that honour a WHERE's
column = valueterms, EXPLAIN plans from its row estimates, and
four environments — production with a replica, staging, a stopped
dev, a local container — whose versions, drift, pending patches,
log errors, sessions and slow queries tell one story.- Redaction mode —
--redact,:redactorredact_default = true
blocks out hosts, IPs, account IDs, ARNs and every server, environment
and secret name pgman knows, on every screen, for screenshots of a
real database; schema and data stay visible.
Hardening before release
A five-reviewer release panel, run four times, found and fixed — each
with a test demonstrated failing first — a hostile-checkout trust model
(a repo's config could once auto-connect with your PGPASSWORD, resolve
an environment variable into a hostname, or relax your safety profile);
a statement lexer that now understands quoted identifiers, $ and
non-ASCII in identifiers, E'' strings and nested comments, refuses a
script it cannot verify, and executes exactly the statements it
checked; passwords with / @ ? # parsed and redacted correctly; an
unknown sslmode refused rather than silently downgraded; a read-only
session that cannot be flipped from inside; bounded and throttled JDBC
tap ingest; owner-only files from the first byte; escapes stripped from
reports and batch output; the placeholder resolver and the DSN parser
agreeing on where a URL's host starts, or refusing the URL; the
read-only floor closed against set_config, a quoted GUC name, DO
and CALL, and a COMMIT mid-script (batch runs inside one explicit
transaction); the picker naming where every credential comes from;
decision modals that no global chord can escape; --demo never
touching your saved queries; and a few dozen first-minute polish
defects found by rendering every screen at five terminal sizes and
by driving the release binary against a live server.
Dependencies
ratatui 0.30, crossterm 0.29, reqwest 0.12 (rustls only), tb-tui-common
0.2 shared with ebman. toml 1.x is used but saved-query files are
written with TOML 1.0-compatible escapes, pinned by test.