Replies: 1 comment 1 reply
-
Hey @Wiz1991, update on this issue: I did some investigation and can say that these Fresh Next.js + Postgres only using the import pg from "pg";
export const getDB = async () => {
if (!globalThis.client) {
console.log("CLIENT CREATE");
const client = new pg.Pool({
connectionString: `postgres://postgres:[email protected]:5432/payloadtests`,
});
client.on("connect", () => {
console.log("CLIENT CONNECT");
});
await client.connect();
globalThis.client = client;
}
return globalThis.client as pg.Pool;
}; import { getDB } from "./db";
export const dynamic = "force-dynamic";
export default async function Home() {
const db = await getDB();
const res = await db.query(`SELECT * FROM payload_migrations`);
return <div>Home</div>
} Important to note that await client.connect(); does get called here only 1 time and then gets cached. We do the same, unless your project is deployed on a serverless platform we do We disabled transactions for read operations so the performance can be potentially better now. I'm converting this to a discussion since it's not an issue but just how underlying |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
No response
Environment Info
Describe the Bug
I was benchmarking the app and noticed that on every single db query, there is a connected pg-pool connect beforehand.
Each connect taking upwards of 20ms, which quickly adds up to response times of 200-700ms (in rare cases 1s+) when doing a data heavy route.
Bear with me, lots of screenshots and will try to include as much info as possible. First of all, here is one page and the queries i do on it server side.
Page.tsx
Moving on inside a child component:
export async function TiersList({ novelId }: { novelId: string }) {
const payload = await getPayload({ config });
}
This is pretty much all the queries I am doing, with one stupid caveat from my side is that i call this
TierList
component twice (one for mobile and one for desktop).This is how the collections look like:
Any relations on this that you see are extremely simple, primary key + 1-2 fields. Nothing else.
That's it. Now the following is the benchmarks i have.
Before each query, there is a pg connect being ran. Each one taking ~20ms
This can be seen here too:

Reproduction Steps
Provided screenshots above
Adapters and Plugins
No response
Beta Was this translation helpful? Give feedback.
All reactions