Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问许可证需确认审计通过

postgresPostgres 数据库

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

1,080

周安装

45

GitHub Stars

1

下载量

360
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:postgres(Postgres 数据库)
来源仓库:https://github.com/alemar11/skills
仓库路径:skills/postgres
安装命令:
npx skills add https://github.com/alemar11/skills --skill postgres
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/alemar11/skills --skill postgres

简介

postgres 连接 PostgreSQL 数据库执行 SQL 查询与 schema 分析。

  • 支持索引优化、查询性能审查与迁移流程管理。
  • 必须通过 shipped scripts/postgres 脚本调用,确保环境隔离。
  • 涉及数据变更时应优先 dry-run 或事务保护,防止丢失数据。
  • postgres 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Postgres

Goal

Use this skill to connect to Postgres, run SQL, inspect schemas, review query performance, design tables and indexes, work with common PostGIS or pgvector patterns, and manage migration release flow through the shipped scripts/postgres artifact in the skill package.

Runtime surface

  • The only supported runtime entrypoint is the shipped scripts/postgres artifact inside this skill package.
  • If your current working directory is the skill root, run it as ./scripts/postgres.
  • If you are invoking the skill from another repo, resolve the skill package path first and run <postgres-skill-root>/scripts/postgres.
  • <postgres-skill-root>/scripts/postgres --version is the runtime version check.
  • Do not use or reintroduce per-task helper scripts from the pre-Rust runtime surface.
  • The implementation lives in projects/postgres/ and is maintenance-only. Normal usage stays on the scripts/postgres surface.
  • Canonical persisted config lives at <project-root>/.skills/postgres/config.toml.
  • This runtime skill does not provide dump, restore, export, or schema-diff workflows. Keep those operator tasks outside this skill.

Fast path

  • Resolve the shipped CLI once and reuse it in commands below:

- POSTGRES_CLI=/path/to/postgres-skill/scripts/postgres

  • Doctor / setup status:

- DB_PROJECT_ROOT=/path/to/repo "$POSTGRES_CLI" --json doctor

  • Bootstrap and save a profile:

- DB_PROJECT_ROOT=/path/to/repo "$POSTGRES_CLI" profile bootstrap --save

  • Resolve the active connection:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" --json profile resolve

  • Run ad-hoc SQL:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" query run -c "select now();"

  • Run a SQL file:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" query run -f./query.sql

  • Safe heredoc for multi-statement SQL / DO $$:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" query run <<'SQL' - select now(); - SQL

  • Connection test:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" profile test

  • Schema introspection:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" schema inspect

  • Object search:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" query find users --types table,column

  • Release a pending migration file:

- DB_PROJECT_ROOT=/path/to/repo DB_PROFILE=local "$POSTGRES_CLI" migration release --summary "Add agent-context prompt sections"

Workflow

  1. Confirm connection source:

- If DB_URL is provided, use it for a one-off connection unless the user explicitly asks to persist it. - Prefer DB_* environment variables. Compatibility inputs such as DATABASE_URL, POSTGRES_URL, POSTGRESQL_URL, and libpq vars (PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD, PGSSLMODE) are also accepted. - PROJECT_ROOT remains unsupported; use DB_PROJECT_ROOT. - If <project-root>/.skills/postgres/config.toml exists, use it. - Else if legacy <project-root>/.skills/postgres/postgres.toml exists, runtime migrates it one-way into canonical config.toml and continues on the canonical path. - During that migration, make sure the consuming repo ignores .skills/postgres/config.toml too; do not leave the canonical file unignored when the legacy postgres.toml had ignore coverage. - If the user explicitly asks to create or refresh a saved profile, use the shipped scripts/postgres artifact from the skill package, for example <postgres-skill-root>/scripts/postgres profile bootstrap.

  1. Choose action:

- Query or inspect data - Inspect schema, indexes, roles, or activity - Review query shape or schema design - Draft or release migrations - Search official PostgreSQL docs only when explicitly requested

  1. Execute and report:

- Return the answer first, then only the supporting context needed to trust it. - Keep backup, restore, export, and schema-diff requests out of this skill's runtime surface.

  1. Persist only if asked:

- Update config.toml only with explicit user approval, except canonical config migration plus explicit profile bootstrap or set-ssl flows. - Treat <project-root>/.skills/postgres/config.toml as local persisted operator config; consuming repos should gitignore it just as they previously gitignored legacy postgres.toml.

Command map

  • doctor

- Validate config resolution and report runtime readiness without mutating config.

  • profile resolve

- Show the active URL, profile, and source.

  • profile bootstrap [--save]

- Interactively create or print a profile.

  • profile test

- Quick connection check.

  • profile info

- Print connection details and key server settings.

  • profile version

- Show server version.

  • profile migrate-toml

- Migrate legacy postgres.toml into canonical config.toml using schema 2.0.0, and ensure ignore coverage follows the canonical file.

  • profile set-ssl <profile> <true|false>

- Persist sslmode for a saved profile.

  • query run

- Execute SQL from -c, -f, or stdin, preserving per-statement results.

  • query explain

- Run EXPLAIN, defaulting to ANALYZE.

  • query find <pattern> [--types...]

- Search schemas, tables, columns, views, and functions by name.

  • activity overview|locks|slow|long-running|cancel|terminate|cancel-pid|terminate-pid|pg-stat-top

- Runtime diagnostics and query-control operations.

  • schema inspect|table-sizes|index-health|missing-fk-indexes|vacuum-status|roles

- Schema and catalog inspection.

  • migration release

- Move a pending migration into released/ and update CHANGELOG.md.

  • docs search

- Search official PostgreSQL current docs.

Config shape

Canonical persisted config uses owner-level config.toml:

schema_version = "2.0.0"

[defaults]
profile = "local"

[tools.postgres]
sslmode = false
migrations_path = "db/migrations"

[tools.postgres.profiles.local]
description = "Local development DB"
host = "127.0.0.1"
port = 5432
database = "app"
user = "postgres"
password = "postgres"
sslmode = false
migrations_path = "db/migrations"

Rules:

  • schema_version is top-level and required in canonical saved configs.
  • Do not add or rely on [meta].
  • Canonical config.toml is local persisted operator config, not normal repo content; consuming repos should gitignore .skills/postgres/config.toml.
  • When migrating from legacy postgres.toml, update ignore rules in the same rollout so the canonical file stays untracked too.
  • [defaults] stores the default saved profile.
  • [tools.postgres] stores shared Postgres defaults.
  • [tools.postgres.profiles.<name>] stores per-profile overrides.

Schema and feature design

  • For schema or table design, start with:

- references/postgres_best_practices/schema-design.md - references/postgres_best_practices/advanced-features.md

  • For geospatial tables, SRIDs, radius search, nearest-neighbor lookups, or spatial indexing, use references/postgres_best_practices/postgis.md.
  • For embeddings, semantic search, similarity search, vector indexes, or retrieval/RAG in Postgres, use references/postgres_best_practices/pgvector.md.

Backend query performance review

  • Inventory read queries separately from write queries before recommending changes.
  • Unless the user explicitly includes writes, optimize only read-side paths.
  • Prioritize:

- N+1 query patterns - repeated correlated subqueries - dynamic IN (...) SQL that should become parameterized arrays - missing composite indexes matching real join and filter predicates

  • Validate with schema and catalog inspection first (schema inspect, schema table-sizes, schema index-health, activity slow) before asking for live benchmarking.

SQL safety

  • Prefer query run with heredoc or -f for multi-statement SQL.
  • Do not inline DO $$... $$ into double-quoted shell strings.

Data-copy migrations

  • When copying selected rows from dev or local into a production SQL file:

- inspect source values and target table shape first - treat copied values as a draft for production - do not preserve generated primary-key values by default - prefer INSERT... RETURNING and stable business keys when dependent rows need new IDs

  • Keep DDL reasoning separate from requested data-copy SQL.

Trigger rules

  • If .skills/postgres/config.toml exists, use it without scanning unless the user asks to bootstrap or refresh.
  • Else if only legacy .skills/postgres/postgres.toml exists, use it as migration input to generate canonical config.toml, and make sure ignore coverage follows the canonical path too.
  • If DB_PROFILE is unset and exactly one profile exists, use it.
  • If multiple profiles exist, prefer the saved [defaults].profile when present; otherwise require an explicit profile or interactive selection.
  • If the user asks to bootstrap or refresh a saved profile, use profile bootstrap.
  • Do not run docs search unless the user explicitly asks for official docs lookup or verification.
  • For migrations path resolution and schema-change workflow, follow references/postgres_guardrails.md.
  • If a pending migration file contains its own BEGIN or COMMIT, do not wrap it in an outer rollback transaction during scratch validation.
  • If the user explicitly marks a pending migration as migrated, released, or run in production, perform migration release immediately unless they ask for a dry run only.
  • Do not use this runtime skill to refresh best-practices references or otherwise upgrade the skill package itself.

Guardrails

  • Always ask for approval before making DDL changes.
  • Keep pending changes in prerelease migration files and maintain a changelog.
  • Use pending migration file and released migration file as the canonical workflow terms.
  • Do not edit existing released SQL files.
  • Do not create a new file under released/ for pending work.
  • Only create a released migration file by moving a pending prerelease file when the user explicitly confirms release.
  • After any schema change, run the least expensive validation query that proves the change landed.
  • For full rules and migration workflow, read references/postgres_guardrails.md.

CLI Maintenance

  • Keep normal execution on the shipped scripts/postgres artifact.
  • Treat projects/postgres/Cargo.toml as the single source of truth for the CLI semver, and use the shipped scripts/postgres --version to verify the runtime version.
  • Open projects/postgres/ only when fixing bugs, improving performance, rebuilding the shipped binary, or extending the CLI contract.
  • Make maintenance changes in projects/postgres/, then rebuild scripts/postgres so the shipped artifact stays current.
  • Treat compiled outputs in projects/postgres/target/ as intermediates, not supported runtime entrypoints.
  • Keep project-local ignore rules in projects/postgres/.gitignore. Only add a skill-root .gitignore if new generated state truly lives at the skill root.
  • Follow semver for shipped CLI changes:

- major for breaking CLI contract changes - minor for backward-compatible new features or meaningful capability additions - patch for backward-compatible bug fixes and corrections

  • After maintenance changes, re-verify through the shipped artifact with:

- from the skill root: ./scripts/postgres --help - from the skill root: ./scripts/postgres --version - from any cwd: DB_PROJECT_ROOT=/path/to/repo <postgres-skill-root>/scripts/postgres --json doctor

  • Keep config migration one-way from legacy postgres.toml to canonical config.toml.
  • Keep the runtime surface focused on query, inspection, and migration release. Do not reintroduce dump, restore, export, or schema-diff commands.

Usage references

  • Setup and runtime usage: references/postgres_usage.md
  • Env var contract: references/postgres_env.md
  • Config schema: references/postgres_skill_schema.md
  • Migration guardrails: references/postgres_guardrails.md
  • Design guidance: references/postgres_best_practices/README.md
  • Local/Docker recovery: references/postgres_local_recovery.md

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.85%
按下载量换算133

Claude

32.5%
按下载量换算117

Cursor

17.58%
按下载量换算63

Gemini CLI

8.89%
按下载量换算32

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills