How to get an agent to write a production-grade Postgres schema
When to use: You want generated SQL that actually survives a code review.
Prerequisites
- Add the pg-aiguide MCP — Point client at https://mcp.tigerdata.com/docs or install the Claude plugin
Flow
-
State the domainI need a schema for a multi-tenant SaaS with orgs, users, projects, invites. Before writing SQL, consult pg-aiguide for schema design and identifier best practices.✓ Copied→ Agent cites view_skill output
-
Review constraints + indexesShow me every constraint you added and why. Any redundant indexes?✓ Copied→ Per-index justification
-
Check modern featuresUse search_docs to verify you're using GENERATED ALWAYS AS IDENTITY (not SERIAL), and NULLS NOT DISTINCT where appropriate.✓ Copied→ Modern idioms applied
Outcome: Schema with sensible constraints, right identity columns, and indexes you can defend.
Pitfalls
- Agent overuses indexes — write-heavy tables slow down — Ask for workload-aware indexing — tell it the expected reads/writes ratio