PostgreSQL Expert - CLAUDE.md Rules for Claude Code
Transform Claude into a PostgreSQL specialist with deep knowledge of schema design, indexing, query planning, transactions, and production operations.
Open the source and read safety notes before installing.
Privacy notes
- Rules reference database URLs and credentials; store connection strings in environment variables or a secrets manager, never in committed application code.
Schema details
- Install type
- copy
- Reading time
- 4 min
- Difficulty score
- 82
- Troubleshooting
- Yes
- Breaking changes
- No
Full copyable content
You are an expert PostgreSQL developer with deep knowledge of relational design,
indexing, query planning, transactions, and production operations.
## Core Philosophy
- Model constraints in the database: primary keys, foreign keys, checks, and unique indexes
- Prefer explicit SQL or query builders you can EXPLAIN over opaque ORM magic
- Design indexes for real query shapes; measure with EXPLAIN (ANALYZE, BUFFERS)
- Treat migrations as production changes with rollback and lock awareness
## Schema Design
```sql
CREATE TABLE orders (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
customer_id bigint NOT NULL REFERENCES customers(id),
status text NOT NULL CHECK (status IN ('pending', 'paid', 'cancelled')),
created_at timestamptz NOT NULL DEFAULT now()
);
```
- Use the right types (`timestamptz`, `numeric`, `uuid`, `jsonb`) deliberately
- Normalize first; denormalize only with measured read-path justification
- Name constraints and indexes so failures are diagnosable in logs
## Query Performance
- Run `EXPLAIN (ANALYZE, BUFFERS)` on slow queries before guessing at indexes
- Watch for sequential scans, nested loops on large sets, and sort/hash spills
- Add composite indexes that match filter + order columns used together
- Keep statistics fresh; understand when partial or covering indexes help
## Transactions and Concurrency
- Keep transactions short; avoid interactive transactions around network calls
- Choose isolation levels intentionally; handle serialization failures with retry
- Use row-level locks (`FOR UPDATE`) only when the business rule requires them
## Operations
- Take backups and test restores; document RPO/RTO expectations
- Use connection pooling; set sane `statement_timeout` and `lock_timeout`
- Plan migrations with concurrent index creation when tables are largeAbout this resource
Usage
Add this rule set to your project's CLAUDE.md to configure Claude as a PostgreSQL expert.
It covers schema design, indexing, EXPLAIN-driven tuning, and transaction safety — grounded in
the PostgreSQL documentation.
Transaction Isolation Levels
When you choose an isolation level, you trade concurrency for guarantees against specific read anomalies. PostgreSQL implements three distinct levels (Read Uncommitted behaves identically to Read Committed). This table reproduces the standard SQL anomaly matrix as documented for PostgreSQL.
| Isolation Level | Dirty Read | Nonrepeatable Read | Phantom Read | Serialization Anomaly |
|---|---|---|---|---|
| Read uncommitted | Allowed, but not in PG | Possible | Possible | Possible |
| Read committed | Not possible | Possible | Possible | Possible |
| Repeatable read | Not possible | Not possible | Allowed, but not in PG | Possible |
| Serializable | Not possible | Not possible | Not possible | Not possible |
Source: Transaction Isolation (Table 13.1).
Sources
Source citations
Add this badge to your README
Show that PostgreSQL Expert - CLAUDE.md Rules for Claude Code is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.
[](https://heyclau.de/entry/rules/postgresql-expert)How it compares
PostgreSQL Expert - CLAUDE.md Rules for Claude Code side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
| Field | PostgreSQL Expert - CLAUDE.md Rules for Claude Code Transform Claude into a PostgreSQL specialist with deep knowledge of schema design, indexing, query planning, transactions, and production operations. Open dossier | Redis Expert - CLAUDE.md Rules for Claude Code Transform Claude into a Redis specialist with deep knowledge of data structures, caching patterns, TTL strategy, pipelining, and production operations. Open dossier | .NET and C# Expert - CLAUDE.md Rules for Claude Code A CLAUDE.md rule set that turns Claude into a senior .NET reviewer aligned with current Microsoft guidance across ASP.NET Core, Entity Framework Core, asynchronous programming, typed options, and automated testing. Open dossier | Django Expert - CLAUDE.md Rules for Claude Code Transform Claude into a Django specialist with deep knowledge of models, views, DRF serializers, migrations, middleware, and production deployment patterns. Open dossier |
|---|---|---|---|---|
| Trust | ||||
| Install risk | Review first | Review first | Review first | Review first |
| Notes | Safety · Privacy ✓ | Safety · Privacy ✓ | Safety · Privacy ✓ | Safety ✓ Privacy ✓ |
| Category | rules | rules | rules | rules |
| Source | source-backed | source-backed | source-backed | source-backed |
| Author | jaso0n0818 | jaso0n0818 | jaso0n0818 | jaso0n0818 |
| Added | 2026-06-16 | 2026-06-16 | 2026-06-13 | 2026-06-14 |
| Platforms | Claude Code | Claude Code | Claude Code | Claude Code |
| Source repo | — | — | — | — |
| Safety notes | — missing | — missing | — missing | ✓These are advisory Django coding rules applied to your project; review migrations, ORM queries, and on_delete cascade choices before running them against a real database. |
| Privacy notes | ✓Rules reference database URLs and credentials; store connection strings in environment variables or a secrets manager, never in committed application code. | ✓Rules reference Redis AUTH passwords and TLS certificates; store them in environment variables or a secrets manager, never in committed config files or client connection strings in source control. | ✓Rules reference dotnet user-secrets and Azure Key Vault for credential storage; secrets must never be committed to source control or hard-coded in application settings files. | ✓Rules reference SECRET_KEY, database credentials, and API tokens; store them in environment variables, never in settings.py committed to git. |
| Prerequisites | — none listed | — none listed | — none listed | — none listed |
| Install | — | — | — | — |
| Config | — | — | — | — |
| Citations | ||||
| Claim | Unclaimed | Unclaimed | Unclaimed | Unclaimed |
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.