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.jsNext.js
  • Node.jsNode.js
  • TypeScriptTypeScript
  • PostgreSQLPostgreSQL
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

    Next.js

    Frontend

    Builds the interface people see and use

    Learning: Moderate

    Status: Active

  • PostgreSQL

    PostgreSQL

    Database

    Stores and queries the data

    Learning: Moderate

    Status: Active

  • Node.js

    Node.js

    Runtime

    Runs the code on the server or device

    Learning: Easy

    Status: Active

  • TypeScript

    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. 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. 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. 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. 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

How quickly a team ships features

Ease of learning
7.0 out of 10, catalog average 7.2

Higher means easier to pick up

Scalability
7.2 out of 10, catalog average 7.6

How far it grows before a redesign

Performance
7.8 out of 10, catalog average 7.5

Speed of the running application

Maintainability
6.8 out of 10, catalog average 7.2

How well the codebase ages

Ecosystem
8.2 out of 10, catalog average 8.2

Libraries, hosting, docs and hiring

Flexibility
8.4 out of 10, catalog average 7.4

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.

Sources

Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.

Stacks that share technologies with Next.js + PostgreSQL.