plain-postgres-doctor

Check overall database health — schema correctness and operational health. Use when asked to check the database, validate schema, optimize indexes, or diagnose Postgres problems.

654 stars

Best use case

plain-postgres-doctor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Check overall database health — schema correctness and operational health. Use when asked to check the database, validate schema, optimize indexes, or diagnose Postgres problems.

Teams using plain-postgres-doctor should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/plain-postgres-doctor/SKILL.md --create-dirs "https://raw.githubusercontent.com/dropseed/plain/main/.claude/skills/plain-postgres-doctor/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/plain-postgres-doctor/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How plain-postgres-doctor Compares

Feature / Agentplain-postgres-doctorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Check overall database health — schema correctness and operational health. Use when asked to check the database, validate schema, optimize indexes, or diagnose Postgres problems.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Database Doctor

Check database health by running schema and operational checks, then fix any issues found.

**All checks are read-only.** Fixes are local code changes. Never run database mutations (`migrations apply`, direct SQL) without explicit user approval.

## 1. Dev only or production too?

Always start by checking the dev database — that's where you are and where fixes get verified. Ask the user if they also want to check production. Production is where schema drift and operational health issues matter most, but dev databases drift too (manual SQL, reverted migrations, branch switches).

If checking production, figure out how the user runs commands there (check for Procfiles, Dockerfiles, deploy scripts, etc.) or ask them. Both `schema` and `diagnose` need to run against the target database.

## 2. Run checks

### Schema correctness

```
uv run plain postgres schema --json
```

Checks whether the actual database matches what the models expect — drift from failed deploys, manual DDL, partial migrations, or branch switches. Also reports unknown tables (tables in the DB with no corresponding model) which are often left over from uninstalled packages.

### Operational health

```
uv run plain postgres diagnose --json
```

Finds unused/duplicate/missing indexes, sequence exhaustion, cache hit ratios, vacuum health, and slow queries. Stats-based checks (unused indexes, cache hit ratios) are most meaningful against production with real traffic. Structural checks (duplicate indexes, missing FK indexes) are valid in any environment.

The JSON output includes `suggestion` fields for each finding. If findings are on unmanaged tables, check whether those tables should exist at all — `schema` will have already flagged them as unknown.

## 3. Fix issues

Make code and migration changes in the local codebase. For app-owned items, this is typically model changes + `uv run plain migrations create`. For unknown tables, present `uv run plain postgres drop-unknown-tables` to the user — it shows what will be dropped and asks for confirmation. Use `--yes` to skip the prompt if the user wants the agent to run it directly. For other unmanaged items, the suggestions include exact DDL — present these to the user for review, do not run SQL directly.

## 4. Verify

For **structural diagnose findings** (duplicate indexes, missing FK indexes): confirm the issue also appears in dev before fixing — you can't verify a fix if you never saw the problem. Run checks before and after the fix, then deploy and re-verify in production.

For **schema drift**: the drift is environment-specific (prod may have manual DDL that dev doesn't). Verify by confirming your fix makes `schema` pass cleanly in dev, then deploy and re-verify in production.

Stats-based findings (unused indexes, cache hit ratios) can only be verified in production after deploy.

Related Skills

plainx-release

654
from dropseed/plain

Releases plainx packages with version suggestions, changelog generation, and git tagging. Use when releasing a package to PyPI.

plain-upgrade

654
from dropseed/plain

Upgrades Plain packages and applies required migration changes. Use when updating to newer package versions.

plain-portal

654
from dropseed/plain

Open a remote Python shell on a production machine via encrypted tunnel. Use when you need to inspect production data, debug issues, run queries, or transfer files.

plain-optimize

654
from dropseed/plain

Captures and analyzes performance traces to identify slow queries and N+1 problems. Use when a page is slow, there are too many queries, or the user asks about performance.

plain-install

654
from dropseed/plain

Installs Plain packages and guides through setup steps. Use when adding new packages to a project.

plain-guide

654
from dropseed/plain

Answer questions about the Plain framework by researching docs and source code. Use when asked "how do I...", "does Plain support...", or "how does X work?" questions.

plain-bug

654
from dropseed/plain

Submit a bug report for the Plain framework. Use when the user wants to report a bug, error, or unexpected behavior. Collects context and creates a GitHub issue.

release

654
from dropseed/plain

Releases Plain packages with intelligent version suggestions and parallel release notes generation. Use when releasing packages to PyPI.

future

654
from dropseed/plain

Navigate and manage the future/ directory — view dependency graphs, filter by arc, find unblocked futures, and identify what to work on next. Use when deciding what to work on, exploring planned work, or checking dependencies between futures.

neon-postgres

31392
from sickn33/antigravity-awesome-skills

Expert patterns for Neon serverless Postgres, branching, connection pooling, and Prisma/Drizzle integration

explainer

3891
from openclaw/skills

Create explainer videos with narration and AI-generated visuals. Triggers on: "解说视频", "explainer video", "explain this as a video", "tutorial video", "introduce X (video)", "解释一下XX(视频形式)".

Content & Documentation

postgresql

31392
from sickn33/antigravity-awesome-skills

Design a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features