Skip to content

Debug history keeps query plans alive even when DEBUG is off #30494

Closed

Description

@mtouchard

Hi! We hit an OOM after moving to Prisma 7 and tracked it down to @prisma/debug.

debugCall pushes every call's arguments into argsHistory (last 100 calls), whether the namespace is enabled or not. In Prisma 7 that includes debug('query plan created', plan) in ClientEngine.ts, plus the SQL and parameters logged by @prisma/adapter-pg. So the plans of roughly the last 25 queries stay in memory, whatever their size.

For big createMany calls that adds up fast: our service (256 MB heap) crashed while inserting 21 batches of 1000 rows. It also partly undoes #29382, which kept createMany plans out of the plan cache because they are so large.

Repro (Prisma 7.10.0, adapter-pg 7.10.0, Postgres 16, Node 24, DEBUG unset): 40 createMany of 1000 rows on a 6-column model, heap measured after global.gc().

after 40 calls
default +81 MB
queryPlanCacheMaxSize: 0 +81 MB
debug histories cleared after each call +11 MB
Script
// node --expose-gc repro.js
const { PrismaClient } = require("@prisma/client")
const { PrismaPg } = require("@prisma/adapter-pg")
const prisma = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }) })
const rows = (k) => Array.from({ length: 1000 }, (_, i) => ({
  label: `row ${k}-${i}`, code: `C${i % 97}`, note: null, amount: "1.25", day: new Date(),
}))

;(async () => {
  global.gc()
  const base = process.memoryUsage().heapUsed
  for (let k = 1; k <= 40; k++) await prisma.row.createMany({ data: rows(k) })
  global.gc()
  console.log(`+${Math.round((process.memoryUsage().heapUsed - base) / 1048576)} MB retained`)
  await prisma.$disconnect()
})()

Model: Row { id Int @id @default(autoincrement()), label String, code String, note String?, amount Decimal @db.Decimal(12, 2), day DateTime }

It's a different cause from #30487: turning the plan cache off changes nothing here.

Suggested fix: when the namespace is disabled, store a short summary of each argument instead of the object itself: strings and primitives as is, errors as name: message, anything else as [Object]. getLogs() still gets useful messages, and the existing @prisma/debug tests pass. With that change applied to both copies, retention stays flat in our runs. Happy to open a PR against v7 if that works for you.

For now we work around it by patching both copies of @prisma/debug with pnpm patch.

Activity

  1. damiommccreary commented on Sep 29, 2026

    @damiommccreary
  2. damiommccreary commented on Sep 29, 2026

    @damiommccreary
  3. damiommccreary commented on Sep 29, 2026

    @damiommccreary
  4. wmadden-electric commented on Nov 19, 2026

    @wmadden-electric
    Contributor

    Fixed on v7 by #30556.

  5. added a commit that references this issue on Nov 20, 2026
    2a93332
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions