Prompt
I'm building a web app with PostgreSQL and Prisma, what should I watch out for?
Latest observation
Nov 1, 2026
OpenAI APIWeb search: off
Here are the main things to watch out for when using PostgreSQL + Prisma in a web app:
1) Migrations can bite you
- Don’t edit applied migrations manually unless you really know what you’re doing.
- Be careful with changing existing columns (type changes, nullability, defaults) because Prisma’s generated migration may not match your production data reality.
- For large tables, some schema changes can lock tables or be expensive:
- adding
NOT NULLcolumns - creating indexes on huge tables
- changing column types
- adding
- Prefer expand/contract migrations for zero-downtime changes:
- add new nullable column / table
- backfill data
- deploy app reading both
- switch writes
- remove old column later
2) Prisma schema ≠ full DB power
Prisma is great, but not everything is modeled perfectly in schema.prisma.
Watch out for:
- advanced PostgreSQL features like:
- partial indexes
- functional indexes
- triggers
- generated columns
- check constraints
- exclusion constraints
- Prisma may not generate or fully manage these, so you may need raw SQL migrations.
3) Query performance and N+1 problems
- Prisma makes it easy to accidentally load too much data.
- Use
selectandincludecarefully. - Avoid fetching entire rows/relations when you only need a few fields.
- Watch for N+1 queries in loops:
- use
include,select, or batch queries when possible.
- use
- Add indexes on columns used in:
whereorderBy- foreign keys
- common joins / filters
4) Transactions matter
- Use transactions when multiple writes must succeed or fail together.
- Prisma supports
prisma.$transaction(...), but be careful with:- long-running work inside transactions
- external API calls inside a transaction
- Keep transactions short to reduce lock contention.
5) Concurrency and race conditions
PostgreSQL is strong, but your app can still race:
- duplicate signups / duplicate records
- two requests updating same row
- “check then insert” bugs
Use:
- unique constraints in the DB
upsertwhere appropriate- transactions or row locking when needed
Don’t rely only on app logic for uniqueness.
6) Unique constraints and null behavior
- PostgreSQL allows multiple
NULLs in unique columns. - If you expect “only one optional value,” that may not behave as you expect.
- Composite unique constraints can behave differently than app logic assumes.
7) Connection management
This is a big one in web apps.
- Too many Prisma clients/connections can overwhelm Postgres.
- In serverless environments, connection storms are common.
Watch out for:
- creating a new PrismaClient on every request
- not reusing the client in dev/hot reload
- serverless DB connection limits
Common fixes:
- reuse a singleton PrismaClient
- use a connection pooler like PgBouncer if needed
- tune deployment model for serverless
8) Raw SQL safety
If you use queryRaw / executeRaw:
- never interpolate user input directly
- use parameterized queries
- be careful with dynamic table/column names
Prisma helps, but raw SQL can still introduce SQL injection if misused.
9) Time zones and timestamps
- Decide early whether you store timestamps in UTC.
- PostgreSQL
timestampvstimestamptzmatters. - Make sure your app, DB, and frontend agree on timezone handling.
- Date bugs are common around:
- DST
- user locale display
- date-only fields
10) Decimal / money types
- Don’t use floating point for money.
- In Prisma/Postgres, use
Decimalfor currency-like values. - Be careful with serialization to JSON and frontend handling.
11) Enum changes are not always painless
- Changing enums in Postgres can be annoying in migrations.
- Removing or renaming enum values requires care.
- Sometimes a lookup table is more flexible than an enum.
12) Database-specific behavior
Postgres is powerful, but Prisma abstracts some things:
- case sensitivity / collation
- JSONB querying
- array fields
- text search
- advisory locks
- CTEs / advanced SQL
If you need one of these heavily, verify Prisma supports your use case cleanly.
13) Seeding and test data
- Keep seed scripts idempotent if possible.
- Tests that rely on exact DB state can become flaky.
- Use a clean test database or reset strategy.
14) Production observability
Make sure you can inspect:
- slow queries
- migration status
- connection usage
- locking / deadlocks
- failed transactions
Logging query duration and enabling Postgres monitoring helps a lot.
15) Backups and recovery
Prisma won’t save you from DB mistakes. Have:
- regular backups
- restore drills
- migration rollback or forward-fix strategy
Practical “best practices” checklist
- Use schema constraints for data integrity
- Add indexes for common queries
- Use
selectto limit returned fields - Reuse PrismaClient
- Use transactions for multi-step writes
- Avoid raw SQL unless necessary; parameterize it
- Plan migrations for production data
- Store times in UTC with
timestamptz - Use
Decimalfor money - Test migrations on a copy of production-like data
If you want, I can also give you:
- a Prisma/Postgres production checklist, or
- a list of common Prisma mistakes and how to avoid them.