The mistake
Assuming PostgreSQL indexes foreign keys. It creates an index for PRIMARY KEY and UNIQUE constraints, but not for the referencing column(s) of a FOREIGN KEY.
Why it is dangerous
Without one, every DELETE (or key UPDATE) on the referenced table has to scan the referencing table to check or cascade matching rows, and joins and filters on the column (WHERE user_id = $1, the usual access path) scan it too. It is invisible on small tables and turns into slow deletes, long lock waits and slow pages as the table grows.
How to fix it
Create an index on the referencing column (concurrently, if the table already holds data), or add @@index([userId]) in Prisma:
CREATE INDEX CONCURRENTLY IF NOT EXISTS orders_user_id_idx ON orders (user_id);A composite index whose first column is the foreign key column also covers it.
What this checker looks for
This page runs pg-launch-check, which reads
SQL migrations, schema.prisma and app code (Prisma, Drizzle, pg, SQLAlchemy, Django). The rules most relevant to this page:
| Rule | What it finds |
|---|---|
PGL001 | Foreign key column without an index |
PGL007 | Table without a primary key |
PGL008 | UUID primary key stored as text |
PGL009 | Money stored as a floating-point type |
PGL010 | timestamp without time zone |
Every finding has a rule id, a severity, file:line, the offending line (secrets masked),
why it matters and how to fix it. Run pg-launch-check rules for the full list.