Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

postgres-query

БесплатноЗапускает вложенные скриптыНе проверен

Run PostgreSQL queries for testing, debugging, and performance analysis. Use when you need to query the database directly, read a query plan (EXPLAIN or…

civitaiот civitai★ 7 333 звезды на GitHub20 установок в других каталогах

Об этом скилле

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 --dev refuses a URL that came from the root .env. A checkout with no skill .env exits 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 prints Server: <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
Полный SKILL.md на GitHub

Установить postgres-query в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.env.examplequery.mjs

FAQ

Что делает скилл postgres-query?

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.

Как установить скилл postgres-query?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл postgres-query запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить postgres-query с