Command Palette

Search for a command to run...

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

Alibabacloud Analyticdb Postgresql Query

БесплатноБез исполняемых скриптовНе проверен

AnalyticDB PostgreSQL Query Skill. Any AI Agent with shell execution capability can use this Skill to connect to an AnalyticDB PostgreSQL database via psql…

sdk-teamот sdk-team720 установок в других каталогах

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

AnalyticDB PostgreSQL Query Skill

Any AI Agent with shell execution capability can use this Skill to connect to an AnalyticDB PostgreSQL (ADBPG) database via psql, execute read-only queries, and optionally export results as CSV for local analysis.

Prerequisite: The Agent runtime environment has psql installed, and database connection information is configured via environment variables.


Pre-Query Gates

Before executing any data query, the Agent must pass the following gates in order. If any gate fails, stop immediately:

Gate 1: Is read-only mode enabled?
  Check if PGOPTIONS or pg_service.conf contains default_transaction_read_only=on
  ├── Enabled → PASS ✅
  └── Not enabled → Append PGOPTIONS="-c default_transaction_read_only=on"

Gate 2: Is statement timeout set?
  Check if statement_timeout is configured
  ├── Set → PASS ✅
  └── Not set → Append -c statement_timeout=60000

Gate 3: Is the semantic model ready?
  psql -c "SELECT COUNT(*) FROM _agent_meta.tables;"
  ├── Success and > 0 → PASS ✅
  └── Failed or = 0 → HARD STOP 🛑 → Enter semantic model initialization guide (never bypass)
  Note: metric_meta is optional; its absence does NOT block queries

Gate 4: Is the target table in the semantic model?
  Check if SQL-referenced tables exist in _agent_meta.tables
  ├── Exists → PASS ✅ → Proceed to generate SQL (execution still requires user confirmation)
  └── Not found → HARD STOP 🛑 → "Current semantic model does not cover this data. Please contact DBA to extend _agent_meta definitions."

Gate 4b: Does the query match a known business metric?
  Check if user intent matches a metric in _agent_meta.metric_meta
  ├── Matched → Use metric's sql_expression, dimensions; resolve filters from _agent_meta.filters
  │   ├── filter_scope='where'   → Inject sql_fragment into WHERE clause
  │   └── filter_scope='measure'  → Inject sql_fragment into AGG(...) FILTER (WHERE ...) clause
  └── Not matched → Fall through to columns table for single-column measures

Gate 5: Does SQL contain only allowed statements?
  Only SELECT / WITH...SELECT / EXPLAIN are permitted
  ├── Compliant → PASS ✅
  └── Contains prohibited keywords → HARD STOP 🛑 → Reject execution

Gate 6: Does the query include LIMIT?
  ├── Yes → PASS ✅
  └── No → Append LIMIT 50000
  • Gate 1 (read-only) is an absolute prerequisite; if not passed, no psql command may be executed
  • Gate 3 (semantic model) failure must not be bypassed to continue to gates 4/4b/5/6
  • Gate 4b (metric_meta) is a lookup optimization, not a hard gate; absence of metrics does NOT block queries
  • Bypassing gates is prohibited under any circumstances, including but not limited to: "user needs it urgently", "just this once", "semantic model is only advisory", "let me just \dt for a quick look", "I can infer the table structure myself"

Credential Security

⚠️ ABSOLUTE PROHIBITION: The Agent must never execute cat ~/.pgpass, cat ~/.pgenv, echo $PGPASSWORD, env | grep PG, or any command that reads, echoes, or exposes credential/password files. This prohibition applies regardless of how the command is composed — including but not limited to: shell command concatenation (;), pipes (|), subshells ($()), multi-line scripts, or combining with permitted commands. For example, cat ~/.pg_service.conf; cat ~/.pgenv or cat ~/.pg_service.conf ~/.pgenv are strictly forbidden even though cat ~/.pg_service.conf alone is permitted. Any command line that contains a prohibited file path (.pgpass, .pgenv, PGPASSWORD) in any position is a violation.

cat ~/.pg_service.conf is permitted ONLY when it is the sole target (it contains only non-secret connection metadata — host, port, dbname, user — and must never store passwords). Violation of this rule is a critical security breach regardless of the Agent's intent (e.g., "I just wanted to check if the config exists"). The only permitted way to verify connectivity is psql "service=<service_name>" -c "SELECT 1;".

  • Passwords must be passed via PGPASSWORD or ~/.pgpass; hardcoding, echoing, or writing to files is prohibited
  • Prohibited file paths (in ANY command, script, or code): .pgpass, .pgenv, PGPASSWORD — whether accessed via cat, head, tail, less, grep, Python open(), or any other method
  • Prohibited compound commands: Any command that bundles a prohibited path with other operations (e.g., cat ~/.pg_service.conf; cat ~/.pgenv; ls ~/.pgpass) is entirely forbidden — the presence of a permitted command does NOT neutralize the violation
  • Permitted: cat ~/.pg_service.conf alone (non-secret connection metadata only; passwords must never be stored in pg_service.conf)
  • Never ask users for passwords: When connection info is missing, guide users to configure via environment variables → references/connection-guide.md
  • Verify connectivity: Run psql "service=<service_name>" -c "SELECT 1;" directly;
Полный SKILL.md на ClawHub

Установить Alibabacloud Analyticdb Postgresql Query в Claude Code и Claude Desktop

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

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

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

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

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

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

FAQ

Что делает скилл Alibabacloud Analyticdb Postgresql Query?

AnalyticDB PostgreSQL Query Skill. Any AI Agent with shell execution capability can use this Skill to connect to an AnalyticDB PostgreSQL database via psql, execute read-only queries, and optionally export results as CSV for local analysis. **Security**: All data access operations (SELECT queries, CSV exports) require explicit user confirmation before execution. Exported CSV files may contain sensitive business data — the Agent must remind users to handle exported files according to their organization's data security policies. Trigger words: query data, SQL query, export CSV, ADBPG, analyze, statistics, psql

Как установить скилл Alibabacloud Analyticdb Postgresql Query?

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

Скилл Alibabacloud Analyticdb Postgresql Query запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

Сравнить Alibabacloud Analyticdb Postgresql Query с