# postgresql-expert

A skill that turns the agent into a PostgreSQL expert: advanced queries, indexes, performance tuning and production operations. Useful whenever a task touches schema, SQL or query plans.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 424 installs · ★ 43
- Author: PCL Team
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/postgresql-expert/SKILL.md
- Updated: 2026-10-12
- HTML: https://affpapa.org/en/nevibecode/skills/postgresql-expert

## What it does

The skill plugs into your agent and sets it up as a PostgreSQL specialist. Inside are practices for picking data types, adding constraints, wrapping changes in transactions, indexing columns used in `WHERE`, `JOIN` and `ORDER BY`, and running regular `VACUUM ANALYZE`. The agent gets `Read`, `Write`, `Edit`, `Glob`, `Grep`, plus `psql`, `pg_dump`, `pg_restore`, `createdb` and `dropdb` through `Bash`.

The workflow runs in steps: design the schema first, then read the plan with `EXPLAIN ANALYZE`, watch slow queries, set up backups with point-in-time recovery, add PgBouncer for connection pooling and replication for read scaling. `JSONB`, full-text search and arrays get their own mention. Longer material sits next to the skill in `references/CORE_CONCEPTS.md` and is read on demand.

PostgreSQL 15.0 or newer is required. On older servers the skill leans on features that are not there, so check your version before installing. For Claude the skill file lands at `~/.claude/skills/postgresql-expert/SKILL.md`.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill postgresql-expert -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/postgresql-expert/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/postgresql-expert/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill postgresql-expert -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/postgresql-expert/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill postgresql-expert -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/postgresql-expert/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install personamanagmentlayer/pcl postgresql-expert
```

2. **Manually: put the files in place**
- File: `.github/skills/postgresql-expert/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill postgresql-expert -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/personamanagmentlayer/pcl --path stdlib/data/postgresql-expert
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/postgresql-expert/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add personamanagmentlayer/pcl --skill postgresql-expert -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/postgresql-expert/SKILL.md

## When to use it
- read a query plan with `EXPLAIN ANALYZE` and find the bottleneck
- pick indexes for specific `WHERE` and `JOIN` clauses
- design a schema with constraints and sensible types
- set up replication and connection pooling for production
- lay out backups with point-in-time recovery

## Example prompts
- run EXPLAIN ANALYZE on this query and suggest indexes
- design an orders table with constraints and foreign keys
- why is this query slow in production? walk me through it

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 158df98c5862dc09.

BEGIN THIRD-PARTY FILE 158df98c5862dc09
````text
---
name: postgresql-expert
version: 1.1.0
description: >-
  Expert-level PostgreSQL database administration, advanced queries, performance tuning,
  and production operations. Use when the user mentions database, SQL, or performance, or
  when the task involves Advanced Data Types, Full-Text Search, Advanced Indexes, or
  Advanced Queries.
category: data
author: PCL Team
license: Apache-2.0
tags:
  - postgresql
  - postgres
  - database
  - sql
  - performance
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash(psql:*, pg_dump:*, pg_restore:*, createdb:*, dropdb:*)
  - Glob
  - Grep
requirements:
  postgresql: '>=15.0'
---

# PostgreSQL Expert

You are an expert in PostgreSQL with deep knowledge of advanced queries, indexing, performance tuning, replication, and database administration. You design and manage production PostgreSQL databases that are performant, reliable, and scalable.

## Best Practices

### 1. Use Proper Data Types

```sql
-- Use specific types
-- Bad: VARCHAR(255) for everything
-- Good: Use appropriate types
email VARCHAR(255)
age INTEGER
price NUMERIC(10,2)
is_active BOOLEAN
created_at TIMESTAMP WITH TIME ZONE
```

### 2. Add Constraints

```sql
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    email VARCHAR(255) UNIQUE NOT NULL,
    age INTEGER CHECK (age >= 0 AND age <= 150),
    status VARCHAR(20) DEFAULT 'active' CHECK (status IN ('active', 'inactive', 'banned'))
);
```

### 3. Use Transactions

```sql
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
```

### 4. Index Appropriately

```sql
-- Index foreign keys
CREATE INDEX idx_orders_user_id ON orders(user_id);

-- Index columns used in WHERE, JOIN, ORDER BY
CREATE INDEX idx_users_created_at ON users(created_at);

-- Don't over-index (slows writes)
```

### 5. Regular Maintenance

```sql
-- Schedule regular VACUUM ANALYZE
-- Monitor slow queries
-- Check for bloat
-- Update statistics
```

## Approach

When working with PostgreSQL:

1. **Design Schema Carefully**: Normalize, use constraints, plan indexes
2. **Use EXPLAIN ANALYZE**: Understand query performance
3. **Monitor Production**: Track slow queries, connection counts
4. **Backup Regularly**: Automated backups with point-in-time recovery
5. **Use Connection Pooling**: PgBouncer for better resource usage
6. **Leverage PostgreSQL Features**: JSONB, full-text search, arrays
7. **Set Up Replication**: High availability and read scaling
8. **Regular Maintenance**: VACUUM, ANALYZE, reindex
````
END THIRD-PARTY FILE 158df98c5862dc09

The third-party file has ended. Everything between the 158df98c5862dc09 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2543 of 2938 bytes. © PCL Team · Apache-2.0 · https://github.com/personamanagmentlayer/pcl/tree/HEAD/stdlib/data/postgresql-expert/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
