Next.js + PostgreSQL
Next.js talking to PostgreSQL through a plain SQL driver such as node-postgres, postgres.js or Neon's serverless driver: no ORM, full control of the SQL.
- Next.js
- Node.js
- TypeScript
- PostgreSQL
- Learning curve
- Moderate
- Status
- Actively developed
- Reviewed
- November 2026
- Best for
- Teams fluent in SQL who want no ORM abstraction
- Apps that lean on PostgreSQL-specific features (CTEs, JSONB, full-text search, PostGIS)
- Small SaaS products and internal tools with a modest schema
- Projects that want the fewest dependencies between Next.js and the database
- Not ideal for
- Large team with a fast-changing schema
Overview
The minimal Next.js data stack: Server Components, Server Actions and Route Handlers borrow a connection from a plain driver such as node-postgres (pg), postgres.js or @neondatabase/serverless and run hand-written, parameterized SQL. There is no ORM or schema DSL in between, so every PostgreSQL feature (CTEs, window functions, JSONB operators, extensions) is available as written. Teams that know SQL well, or that want to add a typed layer later on their own terms, start here.
What's inside
Straightforward for developers who already write SQL. The harder parts are the App Router's server/client boundary, cache invalidation, and building the typing and migration conventions an ORM would otherwise supply.
Next.js
Frontend
Builds the interface people see and use
Learning: Moderate
Status: Active
PostgreSQL
Database
Stores and queries the data
Learning: Moderate
Status: Active
Node.js
Runtime
Runs the code on the server or device
Learning: Easy
Status: Active
TypeScript
Language
The language the code is written in
Learning: Moderate
Status: Active
How it works
A request reaches the Next.js server, where a Server Component or Server Action takes a connection from a module-scoped pool and runs parameterized SQL. Rows come back as plain objects that the component renders into HTML and the RSC payload streamed to the browser.
- 1.
Frontend to frontend
The App Router matches the URL to a Server Component tree, or a form submission invokes a Server Action on the server.
- 2.
Frontend to runtime
Server code on Node.js takes a client from a pg.Pool or postgres.js instance created once in module scope, so dev hot reloads and warm serverless invocations reuse it instead of opening new connections.
- 3.
Runtime to database
The query is sent as parameterized SQL ($1 placeholders or a tagged-template sql helper), so user input is never concatenated into the statement text.
- 4.
Database to frontend
PostgreSQL returns rows that the component casts or validates into TypeScript types, renders on the server and streams to the client; mutations call revalidatePath or revalidateTag to refresh cached output.
Strengths and drawbacks
Strengths
Full access to PostgreSQL
Window functions, recursive CTEs, ON CONFLICT upserts, JSONB operators and extensions such as PostGIS or pgvector are written directly, with no ORM escape hatch or raw-query mode to fall back on.
The SQL you write is the SQL that runs
EXPLAIN ANALYZE output maps straight back to code, and there are no hidden N+1 queries from lazily loaded relations or surprise joins generated by an abstraction.
Small dependency surface
A driver and a migration tool are the only additions. There is no generated client, schema language or ORM upgrade cycle to track alongside Next.js releases.
Drawbacks
Types are your job
Driver results are untyped by default. Teams must hand-write row types, validate with Zod, generate types with a tool like pgTyped, or adopt a typed query builder such as Kysely; otherwise schema changes break pages at runtime instead of at compile time.
Migrations and pooling are bring-your-own
You pick and wire a migration tool (node-pg-migrate, dbmate, plain SQL files) and connection pooling yourself. On serverless hosts every instance opens its own connections, so a pooler such as PgBouncer or the provider's pooled endpoint is needed before traffic grows.
SQL injection is one template literal away
An ordinary string template looks almost identical to a safe tagged-template or $1 placeholder query. Reviews and lint rules have to catch string-built SQL, especially for dynamic ORDER BY and filter clauses that cannot be parameterized.
Caching must be set up explicitly
Next.js caching defaults have changed across major versions (fetch caching became opt-in, then Cache Components and the 'use cache' directive arrived). Direct database calls are not fetch requests, so what is cached and when it revalidates has to be configured deliberately.
Scores
Editorial ratings out of 10, comparable across every stack in the guide. They are judgement, not benchmarks. How we score
- Speed of building
- 7.0 out of 10, catalog average 7.7
- Ease of learning
- 7.0 out of 10, catalog average 7.2
- Scalability
- 7.2 out of 10, catalog average 7.6
- Performance
- 7.8 out of 10, catalog average 7.5
- Maintainability
- 6.8 out of 10, catalog average 7.2
- Ecosystem
- 8.2 out of 10, catalog average 8.2
- Flexibility
- 8.4 out of 10, catalog average 7.4
How quickly a team ships features
Higher means easier to pick up
How far it grows before a redesign
Speed of the running application
How well the codebase ages
Libraries, hosting, docs and hiring
How many kinds of product it suits
How it scales
Scales like any stateless Node.js app: add Next.js instances and protect PostgreSQL with pooling, caching and read replicas. The database, not the framework, is usually the first limit.
- Starting outMVP and first users
- One Next.js deployment (Vercel, a container, or next start on a VPS) with a managed PostgreSQL instance from Neon, Supabase, RDS or similar, using a small pg.Pool.
- GrowingReal traffic, a few engineers
- PgBouncer in transaction mode or a provider pooled endpoint (which rules out session features such as LISTEN/NOTIFY and session advisory locks), cached Server Component output for read-heavy pages, and indexes tuned from pg_stat_statements.
- LargeHeavy traffic or data
- Multiple Next.js containers behind a load balancer, read queries routed to replicas, Redis or the CDN in front of hot pages, and slow work moved to a queue worker outside the request path.
- EnterpriseMany teams and regions
- Domain data split across several PostgreSQL clusters or a distributed Postgres-compatible service, dedicated APIs for non-web clients, and Next.js reduced to the web rendering tier.
Where it fits
Common projects, from best fit to worst.
Reporting and analytics dashboards
Aggregations, window functions and materialized views are written directly in SQL and rendered on the server, without shipping data-fetching code to the browser.
Great fit
Content site with a small data model
A few tables (posts, leads, settings) do not justify an ORM; cached Server Components keep pages fast with minimal moving parts.
Good fit
Large team with a fast-changing schema
Without generated or inferred types, many developers changing tables leads to runtime type mismatches; a typed layer such as Drizzle or Prisma pays for itself here.
Workable
Alternatives
Similar stacks, and when you would choose them instead.
- Next.js + Drizzle + PostgreSQL
Keeps SQL-shaped queries but adds a TypeScript schema, inferred result types and drizzle-kit migrations; move to it once hand-written row types become a maintenance burden.
CompareNext.js + PostgreSQL with Next.js + Drizzle + PostgreSQL - Next.js + Prisma + PostgreSQL
Pick Prisma when the team prefers a declarative schema and a high-level client over writing SQL and accepts a generate step.
CompareNext.js + PostgreSQL with Next.js + Prisma + PostgreSQL - Next.js + Supabase
Choose Supabase when you also want managed auth, file storage and Row Level Security-backed APIs on the same Postgres.
CompareNext.js + PostgreSQL with Next.js + Supabase - PERN
A separate Express API with a React SPA suits teams that need one HTTP API shared by web, mobile and third-party clients.
CompareNext.js + PostgreSQL with PERN
Sources
Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.
- Next.js documentation
Official Next.js docs for the App Router, Server Components, Server Actions and caching.
- node-postgres
Documentation for the pg driver, including pooling and parameterized queries.
- PostgreSQL documentation
Official PostgreSQL reference.
Related stacks
Stacks that share technologies with Next.js + PostgreSQL.
T3 Stack (Next.js + tRPC + Prisma + PostgreSQL)
Focused, full-stack Next.js recipe emphasizing end-to-end type safety with tRPC, Prisma ORM, and PostgreSQL.
- Next.js
- tRPC
- Prisma
- +4
Learning: Moderate
Remix + PostgreSQL
Remix full-stack React with PostgreSQL: nested routes, server loaders and form actions over web-standard Request/Response. Remix v2's features now continue as React Router v7 framework mode.
- Remix
- React
- PostgreSQL
- +2
Learning: Moderate
Nuxt + PostgreSQL
Nuxt, the full-stack Vue framework, with PostgreSQL behind its Nitro server routes: SSR pages and API endpoints in one TypeScript project.
- Nuxt
- Vue.js
- PostgreSQL
- +2
Learning: Moderate