Skip to content

Memory consumption increased significantly in Prisma 7 in comparison to Prisma 6 #29331

Closed

Description

@alexander-eroma

Bug description

We observe significant memory consumption increase after migration from Prisma 6 to Prisma 7 for Postgres.

Severity

🚨 Critical: Data loss, app crash, security issue

Reproduction

Following example can be considered:

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

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

model Sample {
  time     DateTime
  sensorId String

  pressure    Float
  temperature Float

  @@unique([time, sensorId])
  @@index([time])
}

The test script performing following steps:

  1. generate batch of data
  2. insert batch into database (Postgres)
  3. log memory usage
  4. repeat steps 1-3
import 'dotenv/config';
import { PrismaClient, type Sample } from './generated/prisma/client';
import { StatsWriter } from './stats-writer';

const DB_URL = process.env['PRISMA_TEST_POSTGRES_URL'];
const NUM_ITERATIONS = 1_000;
const BATCH_SIZE = 10_000;
const STATS_FILE = 'prisma-6.csv';

const stats = new StatsWriter(STATS_FILE);

const prisma = new PrismaClient({
  datasourceUrl: DB_URL,
});

// in case of Prisma 7
//const prisma = new PrismaClient({
//  adapter: new PrismaPg({ connectionString: DB_URL }),
//});

const nextBatch = (iteration: number, batchSize: number): Sample[] => {
  return Array.from({ length: batchSize }, (_, i) => ({
    time: new Date(iteration * batchSize + i),
    sensorId: Math.random().toString(36).substring(2, 15),
    pressure: Math.random() * 1000,
    temperature: Math.random() * 10,
  }));
};

const runTest = async () => {
  await prisma.sample.deleteMany();

  for (let i = 0; i < NUM_ITERATIONS; i++) {
    const batch = nextBatch(i, BATCH_SIZE);

    const start = process.hrtime.bigint();
    await prisma.sample.createMany({ data: batch });
    const end = process.hrtime.bigint();
    const executionTimeMillis = Number(end - start) / 1_000_000;

    await stats.write({
      iteration: i,
      executionTimeMillis,
      memory: process.memoryUsage(),
    });
  }
};

await runTest();

Expected vs. Actual Behavior

With the test script executed with Prisma 6 and Prisma 7 following results obtained:

Visual charts:

Image Image Image Image Image

In our production workload, we have "bigger" data model (approx 40 attributes) and have NodeJS OOM crash in case of intensive data ingestion.

Frequency

Consistently reproducible

Does this occur in development or production?

Only in production (e.g., query engine, generated client)

Is this a regression?

Workaround

Prisma Schema & Queries

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

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

model Sample {
  time     DateTime
  sensorId String

  pressure    Float
  temperature Float

  @@unique([time, sensorId])
  @@index([time])
}
const runTest = async () => {
  await prisma.sample.deleteMany();

  for (let i = 0; i < NUM_ITERATIONS; i++) {
    const batch = nextBatch(i, BATCH_SIZE);

    const start = process.hrtime.bigint();
    await prisma.sample.createMany({ data: batch });
    const end = process.hrtime.bigint();
    const executionTimeMillis = Number(end - start) / 1_000_000;

    await stats.write({
      iteration: i,
      executionTimeMillis,
      memory: process.memoryUsage(),
    });
  }
};

Prisma Config

import 'dotenv/config';
import { defineConfig } from 'prisma/config';

export default defineConfig({
  schema: 'prisma/schema.prisma',
  migrations: {
    path: 'prisma/migrations',
  },
});

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS: macOS, Linux
  • Database: PostgreSQL
  • Node.js version: v24.14.0

Prisma Version

7.4.2

Activity

  1. idirdev commented on Mar 11, 2026

    @idirdev

    This is a significant regression. Going from ~580MB (Prisma 6) to ~780MB (Prisma 7) on the same workload is a ~35% increase that really matters in containerized environments with tight memory limits.

    A few things worth checking:

    Prisma 7 uses a different client engine (prisma-client generator vs the old prisma-client-js). The new engine might be keeping more internal state per query or not releasing query result buffers as aggressively.

    Your test inserts 10,000 rows per iteration. If Prisma 7 serializes the entire batch differently (e.g. keeping a copy of the input data alongside the query plan), that would explain the linear memory growth.

    The memory chart might show V8 heap growth rather than actual unreclaimable memory. You could try forcing GC between iterations to check:

    // run with --expose-gc flag
    for (let i = 0; i < NUM_ITERATIONS; i++) {
      const batch = nextBatch(i, BATCH_SIZE);
      await prisma.sample.createMany({ data: batch });
    
      if (global.gc) global.gc();
    
      await stats.write({
        iteration: i,
        memory: process.memoryUsage(),
      });
    }

    If memory drops significantly after gc(), its just GC not running often enough. If it stays high, theres a genuine leak.

    As a workaround, try batching the inserts in smaller chunks (1000 instead of 10000). Smaller batches put less pressure on the serialization/buffering path.

  2. alexander-eroma commented on Mar 13, 2026

    @alexander-eroma
    Author

    Hello all.

    Regarding the explicit GC call, for sure it improves the memory consumption and can be considered as a dev env workaround but not prod level solution.

    Also, Prisma 7.5 have been released recently, so i've also included it into charts:

    Image Image Image Image Image

    Average values:

    Metric 6.19.0 7.4.2 7.4.2 gc 7.5.0 7.5.0 gc
    Resident Set Size 477.215 619.135 344.854 660.516 356.61
    Heap total 165.007 499.107 260.597 525.498 271.439
    Heap used 44.7973 306.967 113.398 340.852 122.9
    External memory 3.53869 59.7833 58.1647 60.2901 58.1644
    Array buffers 1.0744 3.55049 1.08233 4.05727 1.08482
  3. added
    bug/1-unconfirmed
    on Mar 16, 2026
  4. bgc-hellen commented on Mar 18, 2026

    @bgc-hellen

    I am facing the exact same issue in Prisma version 7.5

  5. rythelle commented on Mar 19, 2026

    @rythelle

    I have the same problem

  6. solokhind commented on Mar 20, 2026

    @solokhind

    Seeing the same behavior in v7.5. In my case, memory usage continuously increases over time without stabilizing, eventually reaching ~2GB and exhausting the server. Downgrading to v6 resolves the issue.

  7. knzt commented on Mar 20, 2026

    @knzt

    Seeing the same behavior in v7.5. In my case, memory usage continuously increases over time without stabilizing, eventually reaching ~2GB and exhausting the server. Downgrading to v6 resolves the issue.

    Same problem here! also in v7.5

  8. shakim commented on Mar 22, 2026

    @shakim

    Same issue.
    I have also noticed that each call to createMany generates a cache miss even though the row structure stays the same (no undefined or null values)

    # grep cache ~/dev/tmp/prisma.dbg.log   
    prisma:client:clientEngine query plan cache miss +0ms
    prisma:client:clientEngine query plan cache miss +0ms
    prisma:client:clientEngine query plan cache miss +1ms
    prisma:client:clientEngine query plan cache miss +0ms
    prisma:client:clientEngine query plan cache miss +1ms
    prisma:client:clientEngine query plan cache miss +1ms
    prisma:client:clientEngine query plan cache miss +0ms
    prisma:client:clientEngine query plan cache miss +0ms
    prisma:client:clientEngine query plan cache miss +1ms
    ...
    

    Memory usage increases indefinitely to the point of crashing the process.

    <--- Last few GCs --->
    
    [69186:0x9f480c000]    72869 ms: Mark-Compact 4072.6 (4118.5) -> 4066.5 (4120.4) MB, pooled: 0 MB, 448.67 / 0.00 ms  (average mu = 0.270, current mu = 0.156) allocation failure; scavenge might not succeed
    [69186:0x9f480c000]    73423 ms: Mark-Compact 4074.6 (4120.6) -> 4067.9 (4121.8) MB, pooled: 0 MB, 544.67 / 0.00 ms  (average mu = 0.138, current mu = 0.017) allocation failure; scavenge might not succeed
    
    FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
    ----- Native stack trace -----
    
     1: 0x10307083c node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     2: 0x1032704b0 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     3: 0x1034d00e4 v8::internal::Heap::stack() [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     4: 0x1034cdfcc v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     5: 0x1034c2af4 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     6: 0x1034a4200 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     7: 0x103933368 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     8: 0x103f89f74 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
     9: 0x10403cb60 Builtins_CreateTypedArray [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    10: 0x104046310 Builtins_TypedArrayPrototypeSubArray [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    11: 0x12f50ea34 
    12: 0x278f5bb40208 
    13: 0x278f5c065b68 
    14: 0x278f5c064c8c 
    15: 0x278f5c060a24 
    16: 0x278f5c063e00 
    17: 0x278f5c060970 
    18: 0x278f5c06124c 
    19: 0x278f5c05ed68 
    20: 0x278f5c05fdd4 
    21: 0x278f5bcb414c 
    22: 0x103f7fca4 Builtins_JSToWasmWrapperAsm [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    23: 0x10405423c Builtins_JSToWasmWrapper [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    24: 0x12f553638 
    25: 0x12f5537ec 
    26: 0x12f13da84 
    27: 0x12f553a64 
    28: 0x12f553c40 
    29: 0x12f5fb958 
    30: 0x12f44ae34 
    31: 0x12ef3284c 
    32: 0x103f2b648 Builtins_AsyncFunctionAwaitResolveClosure [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    33: 0x1040005f8 Builtins_PromiseFulfillReactionJob [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    34: 0x103f1aa50 Builtins_RunMicrotasks [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    35: 0x103eea7b0 Builtins_JSRunMicrotasksEntry [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    36: 0x1034142e4 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    37: 0x103414b58 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    38: 0x103414c94 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    39: 0x103443b44 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    40: 0x1034444a4 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    41: 0x103eee94c Builtins_CallApiCallbackOptimizedNoProfiling [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    42: 0x12f38b978 
    43: 0x103eea8cc Builtins_JSEntryTrampoline [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    44: 0x103eea570 Builtins_JSEntry [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    45: 0x10341432c v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    46: 0x103413c90 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    47: 0x103288428 v8::Function::Call(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    48: 0x102f710f0 node::InternalCallbackScope::Close() [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    49: 0x102f71320 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context, v8::Local<v8::Value>) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    50: 0x102f85044 node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    51: 0x1031a1f24 node::StreamBase::CallJSOnreadMethod(long, v8::Local<v8::ArrayBuffer>, unsigned long, node::StreamBase::StreamBaseJSChecks) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    52: 0x1031a36b8 node::EmitToJSStreamListener::OnStreamRead(long, uv_buf_t const&) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    53: 0x1031a79e0 node::LibuvStreamWrap::OnUvRead(long, uv_buf_t const*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    54: 0x1031a8110 node::LibuvStreamWrap::ReadStart()::$_1::__invoke(uv_stream_s*, long, uv_buf_t const*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    55: 0x103ed4984 uv__stream_io [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    56: 0x103edcfac uv__io_poll [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    57: 0x103ec935c uv_run [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    58: 0x102f71b44 node::SpinEventLoopInternal(node::Environment*) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    59: 0x1030c4848 node::NodeMainInstance::Run() [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    60: 0x10302a468 node::Start(int, char**) [/Users/shlomo/.nvm/versions/node/v24.14.0/bin/node]
    61: 0x197625d54 start [/usr/lib/dyld]
    error Command failed with signal "SIGABRT".
    

    Environment:

    prisma               : 7.5.0
    @prisma/client       : 7.5.0
    Operating System     : darwin
    Architecture         : arm64
    Node.js              : v24.14.0
    TypeScript           : 5.9.3
    Query Compiler       : enabled
    PSL                  : @prisma/prisma-schema-wasm 7.5.0-15.280c870be64f457428992c43c1f6d557fab6e29e
    Schema Engine        : schema-engine-cli 280c870be64f457428992c43c1f6d557fab6e29e (at ../node_modules/@prisma/engines/schema-engine-darwin-arm64)
    Default Engines Hash : 280c870be64f457428992c43c1f6d557fab6e29e
    Studio               : 0.21.1
    
  9. sdebaene commented on Mar 23, 2026

    @sdebaene

    Same issue here. My app is crashing non stop.

  10. bgc-carlos-henrique commented on Mar 23, 2026

    @bgc-carlos-henrique

    Same issue here!

  11. added a commit that references this issue on Mar 24, 2026
    9d556bd
  12. added a commit that references this issue on Mar 25, 2026
    5b420f8
  13. khalidsaidi commented on Mar 25, 2026

    @khalidsaidi

    A2ABench has an accepted answer for this imported thread.

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

    bug/1-unconfirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions