Skip to main content
If you want a practical way to add PostgreSQL to a Next.js app without running your own database server, DBHost gives you a pooled connection string, a dashboard, daily backups, and API access when you need to automate later. This quickstart keeps to the shortest useful path: one DBHost database, one Prisma client, and one server-side query. Best fit: Small SaaS apps, internal tools, and staging environments that want PostgreSQL working quickly without owning database operations. Not for: Teams that need to manage their own Postgres host, OS, or custom network setup from day one.

What you need

  • A DBHost account and one active database
  • A Next.js app
  • Node.js 18 or later
  • Prisma packages installed in the app
DBHost exposes PostgreSQL through PgBouncer on port 6432. Prisma works with pooled PostgreSQL connections, and Prisma’s PgBouncer guide covers advanced migration setups if you need them later.

1. Create a database in DBHost

Create a database from the dashboard, then copy the connection string from the database detail page. If you are setting up a new project, the DBHost quickstart is still the fastest first step. It gives you the host, port, username, and password you need before you touch your app code.

2. Install Prisma

From your Next.js project:
npm install prisma @prisma/client
npx prisma init
That creates the Prisma schema files and gives you a place to define your PostgreSQL connection.

3. Point Prisma at DBHost

Add the DBHost connection string to .env.local or the environment file your app already uses:
DATABASE_URL="postgresql://uabc123_my_project:PASSWORD@db.dbhost.app:6432/uabc123_my_project?pgbouncer=true"
Use the exact connection details from DBHost. The ?pgbouncer=true flag keeps the pooled connection explicit for Prisma setups that need it.

4. Define a simple schema

Start with a minimal model:
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Project {
  id        String   @id @default(cuid())
  name      String
  createdAt DateTime @default(now())
}
Then push the schema:
npx prisma db push
npx prisma generate
db push is enough for a quickstart. If your team already uses a different Prisma migration flow, keep that workflow and keep the pooled DBHost URL in place.

5. Create a reusable Prisma client

In a Next.js app router project, keep the client in one shared file:
// app/lib/prisma.ts
import { PrismaClient } from '@prisma/client'

const globalForPrisma = globalThis as unknown as {
  prisma?: PrismaClient
}

export const prisma =
  globalForPrisma.prisma ??
  new PrismaClient({
    log: ['error'],
  })

if (process.env.NODE_ENV !== 'production') {
  globalForPrisma.prisma = prisma
}
This keeps development hot reloads from creating a new database client on every refresh.

6. Query from a server component

// app/page.tsx
import { prisma } from './lib/prisma'

export default async function HomePage() {
  const projects = await prisma.project.findMany({
    orderBy: { createdAt: 'desc' },
    take: 5,
  })

  return (
    <main>
      <h1>Projects</h1>
      <ul>
        {projects.map((project) => (
          <li key={project.id}>{project.name}</li>
        ))}
      </ul>
    </main>
  )
}
That is enough to verify the database connection, the Prisma schema, and the Next.js render path in one go.

When DBHost helps most

  • You want PostgreSQL to work with Prisma without managing a VPS
  • You want the pooled connection ready on day one
  • You want backups and password resets from the dashboard later
  • You expect to automate database creation or backup triggers through the published CLI or REST API

Next steps

Start for Free

Create a DBHost account and provision your first database.

Quickstart

Follow the shortest path to your first pooled PostgreSQL database.
  • See the DBHost quickstart for the shortest path to your first database.
  • See the CLI if you want to script database actions from your terminal.
  • See the API reference if your deployment pipeline already speaks HTTP.