postgres-query
FreeRuns bundled scriptsNot checkedRun PostgreSQL queries for testing, debugging, and performance analysis. Use when you need to query the database directly, read a query plan (EXPLAIN or…
About this skill
PostgreSQL Query Testing
Use this skill to run ad-hoc PostgreSQL queries for testing, debugging, and performance analysis.
Running Queries
Use the included query script, and name the target:
node .claude/skills/postgres-query/query.mjs --prod "SELECT * FROM \"User\" LIMIT 5"
node .claude/skills/postgres-query/query.mjs --dev "SELECT * FROM \"User\" LIMIT 5"
Targets
Pick exactly one. Two target flags in one call is an error, not a silent precedence rule, and an
unrecognised option (--devv, --data_packet) is rejected rather than ignored — a swallowed typo
would fall through to the default target, which is production.
| Flag | Connection string | Use when |
|---|---|---|
--prod (default) |
DATABASE_REPLICA_URL, or DATABASE_URL with --writable |
The production main database |
--dev |
DEV_DATABASE_URL |
The dev cnpg database; requires SSH tunnel |
--data-packet |
DATABASE_DATA_PACKET_URL |
The DataPacket replica (read-only) |
--notifications |
NOTIFICATION_DB_REPLICA_URL |
notifications-db (read-only); requires SSH tunnel |
Omitting the target still runs against prod, so old commands keep working — but the run prints
No target flag given, defaulted to --prod. Pass the flag.
Every run prints which database answered
Before connecting, the script writes a line to stderr naming the target, the access mode, the
user@host:port/database pg itself resolved, and the env var it came from:
Target: PROD (read-only) -> <user>@<host>:25061/civitai [DATABASE_REPLICA_URL, timeout 30s]
It prints under --quiet and --json too, and before every exit path that reaches a database —
including a blocked write, so you can always see which database you just aimed a DELETE at. It is
on stderr, so --json piped to a file is still clean JSON.
The host and port come from the client's own resolved connection parameters rather than a re-parse of the string, so the line cannot disagree with where the query actually went.
🔴 Read that line before you trust a result. This skill's .env and the app's root .env both
define DATABASE_URL, and they name different databases — the skill's is production, the root
one is the dev snapshot the dev server uses. The skill's .env wins: it is loaded first, and
loadEnv only fills in keys that are not already present (an empty value counts as present, so
a bare DATABASE_REPLICA_URL= left in this file does not hand that key to the root .env — the
target falls back to this file's DATABASE_URL instead, and the banner says
read-only, but pointed at the primary). So a bare query.mjs answers from production while your
dev server answers from dev. Comparing a value
read here against one read by the running app is comparing two different databases unless both lines
say the same host and port. That cost an hour and produced a confidently wrong root cause on
2026-08-16: limit: 8 from the app's DB and limit: 40 from this skill's, reported as a config bug
that did not exist.
Two checks make the wrong database fail loudly instead of answering:
- Every target except
--devrefuses a URL that came from the root.env. A checkout with no skill.envexits 1 and names the file it would have read. A URL set in the process environment is still accepted: that is a deliberate choice. --prod(read-only) checks that it reached a hot standby. After connecting it printsServer: <addr>, in recovery: <bool>and exits 1 if the server is not in recovery, since a primary or a local copy is not the replica.
Options
| Flag | Description |
|---|---|
--explain |
Show the query plan (EXPLAIN) without running the query |
--explain-analyze |
Run the query and show the plan with actual timings (EXPLAIN ANALYZE) |
--writable |
Use the primary connection instead of the read replica (requires user permission) |
--timeout <s>, -t |
Query timeout in seconds (default: 30) |
--file, -f |
Read query from a file |
--json |
Output results as JSON |
--quiet, -q |
Minimal output, only results |
--explain-analyze executes the statement, so it costs what the query costs. Use --explain to see
the plan and estimated cost of a query you have not yet decided to run.
--timeout is enforced by the server on every read (SET LOCAL statement_timeout inside the
read-only transaction), so a pooled connection cannot drop it. A --writable run has no wrapping
transaction and relies on the statement_timeout connection option, which a transaction pooler
may ignore.
--writable combined with --data-packet or --notifications is an error — both are read-only
replicas, so the combination can only mean a mistake.
Examples
# Simple query
node .claude/skills/postgres-query/query.mjs --prod "SELECT id, username FROM \"User\" LIMIT 5"
# Same query against the dev database
node .claude/skills/postgres-query/query
Install postgres-query in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the postgres-query skill do?
Run PostgreSQL queries for testing, debugging, and performance analysis. Use when you need to query the database directly, read a query plan (EXPLAIN or EXPLAIN ANALYZE), compare query results, or test SQL optimizations. Always pass a target — `--prod` or `--dev` — because prod and dev are different databases and the default is prod. Always uses read-only connections unless explicitly directed otherwise.
How do I install the postgres-query skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the postgres-query skill run scripts?
Yes, this skill bundles executable scripts. Review the source before installing.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic