---
title: "LLM Rules for Postgres"
description: "Six explicit Postgres rules, drawn from building the wispbit review bot, let an LLM code reviewer or coding agent catch common migration and query mistakes before production."
url: "https://swe.quest/articles/llm-rules-for-postgres-ad82e8ad652f6e5a"
canonical: "https://neon.com/blog/llm-rules-for-postgres"
source: "Neon"
published: "2025-08-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["postgres","code-review","schema-migrations","ai-coding","llms"]
---

# LLM Rules for Postgres

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-08-29, 4 min read, How-to. Original: [https://neon.com/blog/llm-rules-for-postgres](https://neon.com/blog/llm-rules-for-postgres)

## Summary

Six explicit Postgres rules, drawn from building the wispbit review bot, let an LLM code reviewer or coding agent catch common migration and query mistakes before production. The rules are to create indexes CONCURRENTLY to avoid write locks, mark columns as ignored in the ORM before dropping them, index every foreign key, require id/created\_at/updated\_at on every table, skip indexes already covered by a composite index, and ensure frequent WHERE conditions have matching indexes. Each comes with bad/good SQL, Prisma or SQLAlchemy examples. Teams are encouraged to add new rules after each incident.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Code review](https://swe.quest/tags/code-review.md) (Engineering practices)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)
- [AI for coding](https://swe.quest/tags/ai-coding.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- Postgres indexes ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- database migrations ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- ORM basics

## Keywords

PostgreSQL, wispbit, Prisma, SQLAlchemy, CREATE INDEX CONCURRENTLY

## Related posts

- [Incident Report: October 28th, 2025](https://swe.quest/articles/incident-report-october-28th-2025-842ec59ef90dc7e9.md): Railway · 2025-10-28 · Medium · 2 min read · PostgreSQL, Schema migrations, Incidents & postmortems, Databases
  A schema migration that added an indexed column to a ~1 billion-row Postgres table without \`CREATE INDEX CONCURRENTLY\` took an exclusive table lock, queuing nearly all backend API queries and taking down Railway's dashboard, CLI, Public API and GitHub webhook deploys for about 40 minutes.
- [Navigating PostgreSQL Locks with Neon and Atlas](https://swe.quest/articles/navigating-postgresql-locks-with-neon-and-atlas-61f1baeebb69a86a.md): Neon · 2025-03-14 · Medium · 11 min read · Schema migrations, PostgreSQL, CI/CD, Static analysis
  Adding a UNIQUE constraint or setting a column NOT NULL in Postgres triggers a full table scan under an ACCESS EXCLUSIVE lock, which blocks all reads and writes and can take down an API on large tables.
- [Dynamic Table Partitioning in Postgres](https://swe.quest/articles/dynamic-table-partitioning-in-postgres-13de90b4fe06270e.md): Supabase · 2023-10-03 · Medium · 20 min read · PostgreSQL, Schema migrations, SQL, Scaling
  Postgres range partitioning can be retrofitted onto an existing "large table" (here, 500 million chat messages) without blocking queries by creating standalone daily child tables, bulk-loading them, adding a CHECK constraint that matches the partition range, and only then running ATTACH PARTITION so Postgres skips the validation scan and its blocking lock.
- [The silent syntax difference in foreign keys between Postgres and MySQL](https://swe.quest/articles/the-silent-syntax-difference-in-foreign-keys-between-postgres-and-mysql-36df1bac8b9567ad.md): Neon · 2024-06-05 · Medium · 6 min read · MySQL, PostgreSQL, SQL, Schema migrations
  MySQL parses but silently ignores inline column-level \`REFERENCES\` clauses, so a foreign key written Postgres-style (\`customer\_id INT REFERENCES customers(customer\_id) ON DELETE CASCADE\`) creates no constraint, no index and no cascade behavior in MySQL.
- [Vibe Coding With AI to Generate Synthetic Data: Part 1](https://swe.quest/articles/vibe-coding-with-ai-to-generate-synthetic-data-part-1-c25e10ea6da5bea8.md): Neon · 2025-03-13 · Medium · 6 min read · AI for coding, LLMs, PostgreSQL, Testing, CI/CD
  Asking Claude to generate synthetic Postgres seed data directly as SQL INSERT statements from a schema-only dump breaks down quickly: claude-3-5-sonnet lost referential integrity somewhere between 20 and 100 rows, and claude-3-7-sonnet often failed with 'model overloaded' errors.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
