PostgreSQL psql
$ psql Official High Riskpsql is the official PostgreSQL command-line client. While famous as an interactive shell, it supports crisp non-interactive agent execution via -c, -X (skip .psqlrc), -v ON_ERROR_STOP=1, --csv, and PostgreSQL's json_agg / row_to_json output.
brew install libpq psql -X -v ON_ERROR_STOP=1 --csv -c "..." is ubiquitous, fast, and scriptable; use PGOPTIONS='-c default_transaction_read_only=on' for guaranteed read-only sessions.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Supports -X, -c, -t -A, --csv, and ON_ERROR_STOP=1, though it lacks a native --json flag (relies on SQL json_agg).
- Supports
-c,--csv,-X, andON_ERROR_STOP=1; no native--jsonflag
Supports server-enforced PGOPTIONS='-c default_transaction_read_only=on' and --single-transaction rollback safety.
- Server-enforced
default_transaction_read_only=onviaPGOPTIONS
Pre-installed or trivially available via libpq / postgresql-client on nearly every OS and CI image.
- Universal OS package availability (
libpq,postgresql-client)
The gold-standard PostgreSQL client for querying, meta-command schema inspection, and COPY streaming.
- Complete PostgreSQL protocol and meta-command support
Official PostgreSQL Global Development Group client maintained for decades.
- Official
postgres/postgrescore client
Exhaustive official man page, though meta-commands and quoting rules have a learning curve.
- Official docs at postgresql.org/docs/current/app-psql.html
Security, Auth & Guardrails
Connection parameters via DATABASE_URL / PGPASSWORD env vars or ~/.pgpass (0600 permissions).
100% free and open-source under the PostgreSQL License.
# psql Agent Rules - Always pass `-X -c "<sql>"` (never start interactive `psql` REPL) and set `PAGER=cat`. - Prefix read queries with `PGOPTIONS='-c default_transaction_read_only=on'`. - For script execution, always pass `-v ON_ERROR_STOP=1` and `--single-transaction`.
Agent-Ready Command Recipes
Safe Read-Only Queries
PGOPTIONS='-c default_transaction_read_only=on' psql "$DATABASE_URL" -X -t -A -c "SELECT coalesce(json_agg(t), '[]'::json) FROM (SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'public' LIMIT 50) t;"
Enforces session-level read-only mode at the server and emits clean JSON via json_agg.
PGOPTIONS='-c default_transaction_read_only=on' psql "$DATABASE_URL" -X --csv -c "SELECT now(), version();"
Outputs RFC-4180 CSV without interactive pager or .psqlrc interference.
Controlled Writes & Previews
psql "$DATABASE_URL" -X -v ON_ERROR_STOP=1 --single-transaction -f migration.sql
Executes a migration script inside a single transaction and aborts on first error.
Strengths for Agents
- +
PGOPTIONS='-c default_transaction_read_only=on'enforces true server-side read-only safety. - +
-v ON_ERROR_STOP=1 --single-transactionprevents half-applied SQL scripts. - +
--csvand-t -Awithjson_aggintegrate cleanly into shell pipelines.
Caveats & Pitfalls
- ! No built-in
--jsonoutput flag; must wrap queries injson_aggor use--csv. - ! Invoking
psqlwithout-cor-fdrops into an interactive REPL and may invoke a pager.