psql
CLIPostgreSQL interactive terminal, used non-interactively for one-shot queries and scripts.
Run SQL against a DATABASE_URL without a client library
Verified commands
Executed by our harness on the platforms shown; the assertion checked the actual result, not just the exit code.
Run one query and print only the value
psql "$DATABASE_URL" -Atc 'SELECT count(*) FROM tools'Common failures (1)
- psql: command not found (macOS)brew install libpq, then use /opt/homebrew/opt/libpq/bin/psql or add that dir to PATH (libpq is keg-only)
List tables
psql "$DATABASE_URL" -c '\dt'Export a query as CSV
psql "$DATABASE_URL" -Atc "COPY (SELECT slug, name FROM tools ORDER BY slug LIMIT 2) TO STDOUT WITH CSV HEADER"Run a .sql file and stop on the first error
psql "$DATABASE_URL" -X -v ON_ERROR_STOP=1 -At -f query.sqlInstall
Homebrew
brew install libpqapt
sudo apt install postgresql-clientAgent notes
- When to use
- Checking row counts, tables, or migrations on a dev/prod Postgres
- Quick examples
psql "$DATABASE_URL" -Atc 'SELECT 1'psql "$DATABASE_URL" -c '\dt'
Use from an agent
curl -s https://clihub.com/api/tools/psql | jq '.agentHints.provenRecipes[] | {task, command, verified}'Or call get_tool with slug psql on the MCP server at https://clihub.com/mcp.