Pgsql Guide Skill logo

Pgsql Guide Skill

Community
jiushiwon
pgsql-guide-skill

PostgreSQL 学习与选型指南。面向需要了解 PostgreSQL 的开发者,提供核心概念、安装部署、表结构设计、索引优化、JSON/数组等高级特性、与业务场景匹配推荐等(不含具体框架集成)。触发词:"PostgreSQL 学习"、"PostgreSQL 入门"、"PostgreSQL 选型"、"pgsql 索引"、"pgsql json"、"pgsql 数组"、"PG 学习"。

Overview

Publisherjiushiwon
Repositorywg-skills
Skill namepgsql-guide-skill
Stars
123
Forks
38
Bundled files
3
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by jiushiwon on GitHub. Read the source before you install it.

Installation

Install the Pgsql Guide Skill AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/database/pgsql-guide-skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jiushiwon/wg-skills.git /tmp/wg-skills
mkdir -p .claude/skills
cp -r /tmp/wg-skills/vibeCoding/backend/database/pgsql-guide-skill .claude/skills/pgsql-guide-skill
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Pgsql Guide Skill in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Pgsql Guide Skill on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Pgsql Guide Skill is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

PostgreSQL Module Skill

面向已有后端项目的开发者,快速集成 PostgreSQL 能力。

能力清单

能力说明
连接配置JDBC/连接池/环境变量配置
表结构设计DDL 建表/字段类型/约束
ORM 映射实体类/Repository/Service
JSON/JSONBJSON 文档存储与查询
数组类型PostgreSQL 原生数组支持
索引优化索引设计/慢查询优化
事务处理声明式/编程式事务
主从复制读写分离/流复制

触发场景

用户说"帮我加 PostgreSQL"或"集成 PostgreSQL"时触发。

核心配置

Java (Spring Boot)

yaml
# application.yml
spring:
  datasource:
    url: jdbc:postgresql://${PG_HOST:localhost}:${PG_PORT:5432}/${PG_DATABASE:myapp}
    username: ${PG_USER:postgres}
    password: ${PG_PASSWORD:}
    driver-class-name: org.postgresql.Driver
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5
      connection-timeout: 30000

Python (FastAPI)

python
# config.py
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    pg_host: str = "localhost"
    pg_port: int = 5432
    pg_user: str = "postgres"
    pg_password: str = ""
    pg_database: str = "myapp"

# database.py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine(
    f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}",
    pool_size=10,
    max_overflow=20,
    pool_pre_ping=True
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Go (Gin + GORM)

go
// config/config.go
package config

import (
    "fmt"
    "os"
)

type Config struct {
    PGHost     string
    PGPort     string
    PGUser     string
    PGPassword string
    PGDatabase string
}

func Load() *Config {
    return &Config{
        PGHost:     getEnv("PG_HOST", "localhost"),
        PGPort:     getEnv("PG_PORT", "5432"),
        PGUser:     getEnv("PG_USER", "postgres"),
        PGPassword: getEnv("PG_PASSWORD", ""),
        PGDatabase: getEnv("PG_DATABASE", "myapp"),
    }
}

func (c *Config) DSN() string {
    return fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai",
        c.PGHost, c.PGUser, c.PGPassword, c.PGDatabase, c.PGPort)
}

func getEnv(key, defaultVal string) string {
    if val := os.Getenv(key); val != "" {
        return val
    }
    return defaultVal
}
go
// database/database.go
package database

import (
    "fmt"
    "log"
    "time"

    "gorm.io/driver/postgres"
    "gorm.io/gorm"
    "gorm.io/gorm/logger"
)

var DB *gorm.DB

func Init(dsn string) {
    var err error
    DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
        Logger: logger.Default.LogMode(logger.Info),
    })
    if err != nil {
        log.Fatalf("连接 PostgreSQL 失败: %v", err)
    }

    sqlDB, _ := DB.DB()
    sqlDB.SetMaxIdleConns(5)
    sqlDB.SetMaxOpenConns(10)
    sqlDB.SetConnMaxLifetime(30 * time.Minute)

    fmt.Println("PostgreSQL 连接成功")
}

表结构设计

基础表模板

sql
CREATE TABLE "wg_user" (
  "id" BIGSERIAL PRIMARY KEY,
  "username" VARCHAR(50) NOT NULL UNIQUE,
  "password" VARCHAR(255) NOT NULL,
  "nickname" VARCHAR(100),
  "avatar" VARCHAR(500),
  "email" VARCHAR(100),
  "phone" VARCHAR(20),
  "status" SMALLINT NOT NULL DEFAULT 1 CHECK (status IN (0, 1)),
  "extra" JSONB DEFAULT '{}',
  "tags" TEXT[] DEFAULT '{}',
  "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "deleted_at" TIMESTAMP
);

CREATE INDEX "idx_wg_user_status" ON "wg_user" ("status");
CREATE INDEX "idx_wg_user_created_at" ON "wg_user" ("created_at");
CREATE INDEX "idx_wg_user_extra" ON "wg_user" USING GIN ("extra");

COMMENT ON TABLE "wg_user" IS '用户表';
COMMENT ON COLUMN "wg_user"."username" IS '用户名';

JSON/JSONB 支持

PostgreSQL 特性

sql
-- JSONB 字段
ALTER TABLE wg_user ADD COLUMN extra JSONB DEFAULT '{}';

-- 查询 JSON 字段
SELECT * FROM wg_user WHERE extra->>'nickname' = '小明';

-- 索引 JSON 字段
CREATE INDEX idx_user_extra ON wg_user USING GIN (extra);

Java

java
@Entity
@Table(name = "wg_user")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(unique = true)
    private String username;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> extra;
    
    @Column(columnDefinition = "text[]")
    private String[] tags;
}

Python

python
from sqlalchemy.dialects.postgresql import JSONB, ARRAY

class User(Base):
    __tablename__ = "wg_user"
    
    id = Column(BigInteger, primary_key=True)
    username = Column(String(50), unique=True, nullable=False)
    extra = Column(JSONB, default={})
    tags = Column(ARRAY(String), default=[])

数组类型

sql
-- 数组字段
ALTER TABLE wg_user ADD COLUMN tags TEXT[] DEFAULT '{}';

-- 查询数组
SELECT * FROM wg_user WHERE 'admin' = ANY(tags);

-- 数组包含
SELECT * FROM wg_user WHERE tags @> '{admin,user}';

索引设计

  1. B-tree 索引:用于 =、<、>、<=、>= 查询
  2. GIN 索引:用于 JSON、数组、全文搜索
  3. GiST 索引:用于地理空间数据
  4. BRIN 索引:用于时间序列数据
sql
-- 复合索引
CREATE INDEX idx_user_status_created ON wg_user (status, created_at DESC);

-- 条件索引
CREATE INDEX idx_user_active ON wg_user (id) WHERE status = 1;

-- JSON 索引
CREATE INDEX idx_user_extra ON wg_user USING GIN (extra);

事务处理

Java

java
@Service
public class UserService {

    @Transactional(rollbackFor = Exception.class)
    public void createUser(User user) {
        userRepository.save(user);
    }
}

Python

python
from sqlalchemy.orm import Session

def create_user(db: Session, user: User):
    with db.begin():
        db.add(user)

不做

  • 不负责 PostgreSQL Server 安装(用户自行安装或使用 Docker)
  • 不处理复杂的集群配置
  • 不提供数据迁移工具

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Pgsql Guide Skill AI skill do?

PostgreSQL 学习与选型指南。面向需要了解 PostgreSQL 的开发者,提供核心概念、安装部署、表结构设计、索引优化、JSON/数组等高级特性、与业务场景匹配推荐等(不含具体框架集成)。触发词:"PostgreSQL 学习"、"PostgreSQL 入门"、"PostgreSQL 选型"、"pgsql 索引"、"pgsql json"、"pgsql 数组"、"PG 学习"。

Why use Pgsql Guide Skill on TypingMind?

Because you install it once and use it with any model. Pgsql Guide Skill is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Pgsql Guide Skill in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/database/pgsql-guide-skill. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Pgsql Guide Skill?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Pgsql Guide Skill?

As many as you like. As long as a model supports skills, you can use Pgsql Guide Skill with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Pgsql Guide Skill AI skill free?

Yes. It is published on GitHub by jiushiwon under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇