Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计通过

mastering-postgresqlmastering PostgreSQL 搜索

Agent Skill

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

总安装

667

周安装

27

GitHub Stars

3

下载量

210
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/spillwavesolutions/mastering-postgresql-agent-skill --skill mastering-postgresql

简介

mastering-postgresql 用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。

  • 适合让 Agent 分析 schema、编写 SQL、排查查询问题或整理索引。
  • 使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更。
  • 涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

PostgreSQL Python Development

Build search, vector similarity, and data-intensive applications with PostgreSQL and Python.

Quick Reference

TaskGo To
Docker/local setupsetup-and-docker.md
Full-text search & BM25search-fulltext.md
pgvector & JSONB indexingsearch-vectors-json.md
Python drivers & poolspython-drivers.md
Python query patternspython-queries.md
AWS RDS/Auroracloud-aws.md
GCP Cloud SQL/AlloyDBcloud-gcp.md
Azure Flexible Servercloud-azure.md
Neon & Supabasecloud-serverless.md
Cloud common (pooling, config)cloud-common.md

When NOT to Use This Skill

  • DBA tasks: Backup strategies, replication setup, user management, security hardening
  • Other databases: MySQL, MongoDB, Redis, Elasticsearch-specific queries
  • Schema design: Normalization theory, data modeling patterns
  • Stored procedures: PL/pgSQL function development
  • Application frameworks: Django ORM specifics, FastAPI integration details

Quick Start Checklist

Copy this checklist to track progress:

Setup Progress:
- [ ] Docker environment running (docker-compose up -d)
- [ ] Connected to database (psql or Python)
- [ ] Extensions created (pgvector, pg_trgm)
- [ ] Table created with search_vector and embedding columns
- [ ] GIN index on search_vector created
- [ ] HNSW index on embedding created
- [ ] Test full-text query returns results
- [ ] Test vector query returns results

Quick Start: Search + Vectors in 5 Minutes

1. Start PostgreSQL with pgvector

# docker-compose.yml
services:
  postgres:
    image: pgvector/pgvector:pg17
    environment:
      POSTGRES_PASSWORD: devpass
    ports: ["5432:5432"]
    volumes: [pgdata:/var/lib/postgresql/data]
volumes:
  pgdata:
docker-compose up -d

# Verify container is running:
docker-compose ps
# Expected: postgres service with status "Up"

2. Enable Extensions

CREATE EXTENSION vector;      -- pgvector for embeddings
CREATE EXTENSION pg_trgm;     -- Trigram for fuzzy search

-- Verify extensions installed:
SELECT extname, extversion FROM pg_extension
WHERE extname IN ('vector', 'pg_trgm');
-- Expected: 2 rows with version numbers

3. Create Searchable Table with Vectors

CREATE TABLE documents (
    id BIGSERIAL PRIMARY KEY,
    title TEXT NOT NULL,
    content TEXT,
    embedding vector(1536),
    search_vector tsvector GENERATED ALWAYS AS (
        setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
        setweight(to_tsvector('english', coalesce(content, '')), 'B')
    ) STORED
);

-- Create indexes
CREATE INDEX idx_docs_search ON documents USING GIN (search_vector);
CREATE INDEX idx_docs_embedding ON documents USING hnsw (embedding vector_cosine_ops);

-- Verify indexes created:
SELECT indexname FROM pg_indexes WHERE tablename = 'documents';
-- Expected: idx_docs_search, idx_docs_embedding, documents_pkey

4. Query from Python

import asyncpg

async def search(pool, query: str, embedding: list[float], limit: int = 10):
    return await pool.fetch("""
        SELECT id, title,
               ts_rank(search_vector, websearch_to_tsquery('english', $1)) AS text_rank,
               embedding <=> $2::vector AS vector_dist
        FROM documents
        WHERE search_vector @@ websearch_to_tsquery('english', $1)
        ORDER BY vector_dist
        LIMIT $3
    """, query, embedding, limit)

# Verify connection works:
# pool = await asyncpg.create_pool('postgresql://postgres:devpass@localhost/postgres')
# rows = await pool.fetch("SELECT 1 AS test")
# assert rows[0]['test'] == 1

Decision Trees

Which Search Approach?

Need search? ─┬─► Exact keyword match ──────► B-tree index + WHERE =
              │
              ├─► Full-text search (FTS) ───► tsvector + GIN + ts_rank
              │
              ├─► Relevance like Google ────► pg_search BM25 (ParadeDB)
              │
              ├─► Typo tolerance ───────────► pg_trgm + similarity()
              │
              ├─► Semantic/AI search ───────► pgvector + embeddings
              │
              └─► Hybrid (keywords + semantic) ► Combine tsvector + pgvector

Which Vector Index?

Vector index? ─┬─► Dataset < 100K rows ────► No index (exact search OK)
               │
               ├─► Need best recall ────────► HNSW (slower build, fast query)
               │
               ├─► Fast index build ────────► IVFFlat (needs data first)
               │
               ├─► On AlloyDB ──────────────► ScaNN (Google optimized)
               │
               ├─► On Azure ────────────────► pg_diskann (32x less memory)
               │
               ├─► Billions of vectors ─────► VectorChord vchordrq (self-host)
               │
               └─► Dimensions > 2000 ───────► halfvec or binary quantization

Which Python Library?

Python lib? ──┬─► Sync, simple, stable ─────► psycopg2
              │
              ├─► Async + modern features ──► psycopg3
              │
              ├─► Max async performance ────► asyncpg
              │
              └─► ORM needed ───────────────► SQLAlchemy + asyncpg/psycopg

Which Index Type for Column?

Column type? ─┬─► Scalar (int, text, timestamp) ─► B-tree (default)
              │
              ├─► JSONB ────────────────────────┬► GIN (general queries)
              │                                 └► GIN jsonb_path_ops (@> only)
              │
              ├─► Array ────────────────────────► GIN
              │
              ├─► tsvector ─────────────────────► GIN (or GiST for updates)
              │
              ├─► vector ───────────────────────► HNSW or IVFFlat
              │
              └─► Range / Geometric ────────────► GiST

Common Patterns

For implementation details, see the reference files:

Index Tuning Quick Reference

HNSW Parameters

ParameterDefaultGuidance
m16Higher = better recall, more memory. 12-48 typical
ef_construction64Higher = better index quality, slower build. 64-200
hnsw.ef_search40Set at query time. Higher = better recall, slower
CREATE INDEX ON docs USING hnsw (embedding vector_cosine_ops) WITH (m=16, ef_construction=100);
SET hnsw.ef_search = 100;  -- Before querying

-- Verify setting applied:
SHOW hnsw.ef_search;

IVFFlat Parameters

ParameterGuidance
listssqrt(rows) for <1M rows; rows/1000 for >1M
ivfflat.probesStart at sqrt(lists), increase for recall
CREATE INDEX ON docs USING ivfflat (embedding vector_l2_ops) WITH (lists=100);
SET ivfflat.probes = 10;

Troubleshooting Quick Reference

SymptomLikely CauseFix
Seq Scan on indexed columnStats outdatedANALYZE tablename;
Vector search slowNo index or low ef_searchCreate HNSW index, increase ef_search
Poor vector recallIVFFlat probes too lowIncrease ivfflat.probes
FTS not matchingWrong language configCheck to_tsvector('english',...)
Index not usedQuery doesn't match opsVerify operator class matches query
Connection timeoutPool exhaustedIncrease pool size or fix leaks
Extension not foundNot installedCREATE EXTENSION name;
HNSW build OOMInsufficient memoryIncrease maintenance_work_mem
Filtered queries return few resultsFiltering after index scanEnable hnsw.iterative_scan
Connection drops in productionNo health checkingUse check=ConnectionPool.check_connection
Scaling past 100M vectorspgvector limitsConsider VectorChord vchordrq

For detailed troubleshooting, see search-vectors-json.md.

Script Usage

pip install -r scripts/requirements.txt  # Install dependencies first
ScriptPurposeWhen to Use
setup_extensions.pyInstall pgvector, pg_trgm extensionsInitial database setup
create_search_tables.pyCreate tables with search_vector and embedding columnsAfter extensions installed
health_check.pyCheck index health, bloat, and performanceDiagnosing slow queries
vector_search.py --demoDemonstrate vector similarity queriesLearning pgvector patterns
bulk_insert.pyHigh-performance data loadingImporting large datasets
fts_examples.pyFull-text search query examplesLearning FTS syntax
connection_pool.pyConnection pooling patternsProduction deployments

Example:

python scripts/setup_extensions.py --host localhost --dbname mydb
python scripts/create_search_tables.py --host localhost --dbname mydb
python scripts/health_check.py --host localhost --dbname mydb

Cloud Quick Reference

ProviderpgvectorBM25 SupportConnection Pooling
AWS RDS/Aurora0.8.0pg_textsearch (preview)RDS Proxy
GCP Cloud SQL0.8.0pg_textsearch (preview)Cloud SQL Proxy
GCP AlloyDB0.8.0 + ScaNNpg_textsearch (preview)Built-in
Azure Flexible0.8.0 + pg_diskannpg_textsearch (preview)Built-in PgBouncer
Neonpg_searchBuilt-in
Supabasepg_searchBuilt-in

Serverless options: Neon (scale-to-zero, instant branching) and Supabase (BaaS with auth/real-time) are ideal for dev/test and startups. See cloud-serverless.md.

BM25 Options:

  • pg_search (ParadeDB): Production-ready, self-host or ParadeDB managed service
  • pg_textsearch (TigerData): Preview status, available on managed PostgreSQL services

See provider-specific files for setup commands: AWS | GCP | Azure

Reference Files

Load these for detailed implementation guidance:

ReferenceLoad When
setup-and-docker.mdDocker setup, extension installation, postgresql.conf tuning
search-fulltext.mdFull-text search (FTS), BM25 setup, trigram fuzzy search
search-vectors-json.mdpgvector tuning, JSONB/array indexing, maintenance
python-drivers.mdpsycopg2/psycopg3/asyncpg, connection pools, SQLAlchemy
python-queries.mdBulk inserts, FTS queries, vector queries, JSONB operations
cloud-aws.mdAWS RDS/Aurora setup, RDS Proxy
cloud-gcp.mdGCP Cloud SQL/AlloyDB, ScaNN indexes
cloud-azure.mdAzure Flexible Server, pg_diskann
cloud-serverless.mdNeon, Supabase (scale-to-zero, branching)
cloud-common.mdExtension matrix, pooling, production config, costs

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.28%
按下载量换算74

Claude

28.26%
按下载量换算59

Cursor

20.23%
按下载量换算42

Gemini CLI

10.34%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

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

来源信息

继续浏览同类 Skills