Replies: 4 comments
|
Hi @jekh! Thank you for raising this. This is not a known issue. I have shared it with our Prisma ORM team internally to get insights on what could cause this behaviour. One possible hunch could be missing statement cache in Driver Adapters. I'll get back to you on this. |
|
I did finally get around to investigating this, since the issue is still occurring. The problem is indeed missing the prepared statement name in Driver Adapters. Here's a repro: https://github.com/jekh/prisma-stmt-test And a PR to fix it: #29337 The TL;DR of the fix is probably this:
It results in an 80+% reduction in SQL text over the wire, and a significant reduction in CPU. |
|
This is worth opening as a bug or performance regression report. A 10x increase in traffic from the app to Postgres does not sound like something that should be explained only by switching from the Rust query engine to A few things I would check first: Pool configuration With DATABASE_URL="postgresql://user:password@host:5432/db?connection_limit=10&pool_timeout=10"Instead, configure the import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
idleTimeoutMillis: 300_000,
connectionTimeoutMillis: 5_000,
});
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });If you have multiple Node processes or containers, Query shape I would also compare actual SQL emitted before and after the switch. Enable query logging in both versions and check whether the adapter version is producing more SQL statements for the same request path: const prisma = new PrismaClient({
adapter,
log: ["query", "warn", "error"],
});If the traffic increase is from more statements, that points toward a Prisma client engine or query compiler difference. If the number of statements is the same but bytes sent to Postgres are much higher, that points more toward protocol, parameter encoding, prepared statement, or driver behavior. Native libpq I would not assume What would make this actionable The most useful reproduction would be: And then one representative endpoint or job with: My guess is that this is not simply “you forgot pg-native.” The first thing I would suspect is that the switch changed either pooling defaults or the generated SQL/query execution path. If the query count is identical but network bytes explode, that would be a strong signal for an adapter or driver level regression. |
|
This is a real, confirmed issue — not a misconfiguration on your end. The root cause has been identified and a fix PR has been submitted. Root cause — missing prepared statement names in the Driver Adapter pathThe problem is that Without the Driver Adapter (Rust query engine): With This directly explains both observations in your metrics:
StatusThe original poster investigated this and confirmed the root cause — the fix is in PR #29337 against the Prisma repo. As of this writing, the fix has not yet been merged into a release. You can track PR #29337 to know when it lands. What to do right nowOption 1 — Revert to the Rust query engine until the fix is released Remove Option 2 — Stay on the Driver Adapter path but reduce impact with explicit pool configuration If you need to stay on the adapter path, make sure you are configuring the import { Pool } from 'pg';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from './generated/prisma/client';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10, // size per process/container
idleTimeoutMillis: 300_000,
connectionTimeoutMillis: 5_000,
});
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
Option 3 — Enable query logging to quantify the impact on your specific workload const prisma = new PrismaClient({
adapter,
log: ['query', 'warn', 'error'],
});Compare the number of SQL statements and the byte size of queries between the Rust engine and adapter paths to confirm the exact multiplier in your workload. If your queries are narrow (few columns, short SQL), the impact will be smaller than for wide-table queries. On your question about
|
| Question | Answer |
|---|---|
| Is this a known issue? | Yes — confirmed by both a Prisma maintainer and the original poster's own investigation |
| Root cause | @prisma/adapter-pg sends unnamed prepared statements, causing full SQL text to be sent on every query execution instead of a short cached statement name |
| Expected traffic reduction after fix | 80%+ reduction in SQL bytes over the wire |
| Fix available? | PR #29337 submitted — not yet released as of this writing |
Should you use pg-native? |
No — unrelated to this issue |
| Recommended action now | Revert to Rust engine for production until PR #29337 lands in a release |
Hope this helps — if it answers your question, would you mind clicking "Mark as answer" so others searching for the same thing can find it quickly?
Uh oh!
There was an error while loading. Please reload this page.
Question
On 6.19.0, I recently updated to use
@prisma/adapter-pg, in preparation for 7.0. I immediately noticed that network traffic to Postgres went through the roof, a >10x increase in production, with a corresponding significant (~+50%) CPU increase.Is this a known issue? Is there maybe some node-postgres setting I missed or something? This huge of a difference seems like it has to be a misconfiguration. You can clearly see the switch to driver adapters, and the switch back, with no other changes in between:
Running node 24 on Alpine, against an AWS RDS Postgres instance. I am not using native libpq with
@prisma/adapter-pg-- is that recommended? The provider in both cases isprovider = "prisma-client", the only difference isengine-type="client"when using the driver adapter, and of course providing the adapter to PrismaClient.How to reproduce (optional)
No response
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
No response
All reactions