postgres-cli
Original:🇺🇸 English
Translated
3 scripts
Execute PostgreSQL queries and introspection with named project connections using `postgres-cli` V2. Use when the user asks to inspect data, run SQL, debug schema, validate config, or build schema cache artifacts.
43installs
Sourcedobby/postgres-cli-skill
Added on
NPX Install
npx skill4agent add dobby/postgres-cli-skill postgres-cliTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Postgres CLI (V2)
Use to query PostgreSQL through named connection targets.
postgres-cliPlatform Support
- is a launcher script.
scripts/postgres-cli - Prebuilt binaries are expected in for:
scripts/bin/- macOS arm64 ()
postgres-cli-darwin-arm64 - Linux x86_64 ()
postgres-cli-linux-x86_64 - Windows x86_64 ()
postgres-cli-windows-x86_64.exe
- macOS arm64 (
- If no compatible binary exists and source + Cargo are available, launcher falls back to .
cargo run --release
Available Scripts
- - Launcher that selects a platform binary.
scripts/postgres-cli - - Builds and places a binary for current host into
scripts/build-release-binary.sh.scripts/bin/ - - Downloads release binaries into
scripts/refresh-binaries-from-release.sh <tag>.scripts/bin/
When To Use
- The user asks to inspect Postgres data.
- The user asks to run SQL against a configured target.
- The user asks for schema introspection.
- The user asks to validate DB CLI config or debug connectivity.
- The user asks to refresh schema cache for agent context.
Setup
Read Setup Guide.
V2 Command Contract
Global flags (before subcommand):
- (optional; default cwd)
--project-root <path> - (optional if
--target <name>set)default_target - (default
--format <json|text|csv|tsv>)json - (optional output file)
--output <path> - (suppresses text summary)
--no-summary
Subcommands:
query- input: exactly one of ,
--sql,--sql-file--stdin - flags: (default
--mode <read|write>),read--timeout-ms
- input: exactly one of
explain- input: exactly one of ,
--sql,--sql-file--stdin - flags: ,
--analyze,--verbose,--buffers,--settings,--wal--timeout-ms
- input: exactly one of
introspect- required:
--kind <schemas|tables|columns|indexes|constraints|views|materialized-views|functions|triggers|enums|rowcounts|rowcounts-exact> - optional filters: (repeatable),
--schema(repeatable)--table schema.table
- required:
schema-cache update- flags: ,
--all-tables,--with-markdown,--table-file-naming <table|schema-table>--timeout-ms
- flags:
targets listconfig validatedoctor
Safety Rules
- Prefer read targets for normal data inspection.
- blocks mutating SQL.
query --mode read - Mutating SQL requires and
query --mode writeon target.allow_write=true - on mutating SQL requires write-enabled target.
explain --analyze
Command Patterns
Run read query:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read query --sql "SELECT now();"Run write query intentionally:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-write query --mode write --sql "UPDATE users SET active = true WHERE id = 1;"Introspect tables:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read introspect --kind tablesExplain a query:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read explain --sql "SELECT * FROM users WHERE id = 1;"Validate config:
bash
scripts/postgres-cli --project-root /path/to/repo config validateDoctor connectivity:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read doctorUpdate schema cache (JSON only):
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read schema-cache updateUpdate schema cache with markdown:
bash
scripts/postgres-cli --project-root /path/to/repo --target webshop-read schema-cache update --with-markdownProgressive Schema Loading
When schema context is needed, use this order:
- Read .
.agent/postgres-cli/schema/index.json - Load only required files from .
.agent/postgres-cli/schema/tables/*.json - Read when join/relationship reasoning is needed.
.agent/postgres-cli/schema/relations.json - If markdown was generated, consult files only for human-friendly display.
.md - If cache is missing or stale, run .
schema-cache update
Agent Guidelines
- Always pass unless
--targetis known and stable.default_target - Default to for machine parsing.
--format json - Prefer unless the user explicitly requests data mutation.
query --mode read - Return relevant result rows and summarize key findings.