Official PostgreSQL terminal for running SQL, inspecting schema objects, importing or exporting data, and scripting database admin tasks.
$brew install libpq
AI Analysis
psql is PostgreSQL's official command-line client for interactive SQL, batch execution, and database introspection. It covers day-to-day querying plus admin and data movement tasks without requiring a separate GUI.
What It Enables
- Run ad hoc SQL or script files against PostgreSQL, including variable-driven scripts and single-transaction batch runs for repeatable admin work.
- Inspect databases, schemas, tables, indexes, roles, and server settings with
\d-style meta-commands and hidden-query debugging via-E. - Import or export data and chain follow-up shell steps with
\copy, output redirection,\gset, and repeated query execution through\watch.
Agent Fit
-c,-f, stdin,-X,-v, and documented exit codes make it reliable in scripts, CI jobs, and inspect or change or verify loops.- No native JSON flag is built in, so automation usually relies on SQL-generated JSON or text and CSV modes such as
--csv,-A,-t, and custom separators. - Strong fit when an agent already has database connectivity and enough schema context to issue direct SQL instead of going through a higher-level API.
Caveats
- You need working PostgreSQL credentials and network access first, and many useful workflows still depend on knowing the target schema well enough to write safe SQL.
- Default interactive behavior and user
~/.psqlrcsettings can affect output or prompts, so unattended runs should use-Xand explicit formatting flags.