Skip to content
Back to skills

Postgres Best Practices

ASecurity

Use when writing, reviewing or optimizing PostgreSQL schema, queries or indexes. Integrity in the database, indexes that match queries, EXPLAIN before shipping, no per-item queries.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 11, 2026
ai-agentssqlexpressdatabase

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add mvbsoft/keel --skill postgres-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Postgres Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Postgres Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mvbsoft-postgres-best-practices/badge)](https://www.skillsdirectory.com/skills/mvbsoft-postgres-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: postgres-best-practices
description: Use when writing, reviewing or optimizing PostgreSQL schema, queries or indexes. Integrity in the database, indexes that match queries, EXPLAIN before shipping, no per-item queries.
---

# PostgreSQL best practices

## Easy to miss
- Moving existing rows with their ids: use `GENERATED BY DEFAULT AS IDENTITY` (ALWAYS rejects explicit
  ids) and `setval` the sequence after the copy.
- Never ship a schema file nobody ran: apply it to a throwaway database, or say clearly that it was
  not run.

- **Integrity first:** enforce invariants in the database: `NOT NULL`, foreign keys, `UNIQUE`,
  `CHECK`. Normalize by default; denormalize only with a measured reason.
- **Types:** `timestamptz`, never naive timestamps; `bigint` or `uuid` surrogate keys with natural
  `UNIQUE` constraints; real columns over JSON unless the shape is truly dynamic.
- **Indexes:** on columns used in `WHERE`, `JOIN` and `ORDER BY`; composite column order matches the
  predicates; partial or expression indexes where queries filter that way; don't over-index tables
  with heavy writes.
- **Verify:** `EXPLAIN (ANALYZE, BUFFERS)` for a hot query: no full scan on a large table, sane row
  estimates, no nested-loop blow-up.
- **No per-item queries:** batch with `IN`, `ANY` or joins; use the ORM's eager loading.
- **JSONB:** `jsonb`, not `json`; GIN index on queried paths; don't hide relational data in JSON.
- **Vector search (pgvector):** choose `hnsw` or `ivfflat` deliberately and tune recall versus
  latency; results are approximate, so validate them.
- **Connections and transactions:** use pooling; keep transactions short; never hold a connection
  across an external call.
- **Migrations:** see `migration-safety`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.