psql

CLI

PostgreSQL interactive terminal, used non-interactively for one-shot queries and scripts.

Run SQL against a DATABASE_URL without a client library

4 of 4 recipes verified by execution · 2026-09-17#postgres#sql#database#csv

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

Verified macOS · Linux · 2026-09-17
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

Verified macOS · Linux · 2026-09-17
psql "$DATABASE_URL" -c '\dt'

Export a query as CSV

Verified macOS · Linux · 2026-09-17
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

Verified macOS · Linux · 2026-09-17
psql "$DATABASE_URL" -X -v ON_ERROR_STOP=1 -At -f query.sql

Install

Homebrewbrew install libpq
aptsudo apt install postgresql-client

Agent 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.

Homepage ↗PostgreSQL0 views