N
Neon12mo ago
complex-teal

Terminating connection due to administrator command

hi! We are using drizzle + node in aws lambda and we are constantly hit by the Terminating connection due to administrator command error. I understand why it happens due to neon compute being suspended due to inactivity. From my understanding the best solution is for the client to reconnect to the db in case when this happens, however i'm not exactly sure how to achieve this following the neon docs. Here is how db connection pool is created:
import { drizzle } from 'drizzle-orm/neon-serverless'

const pool = new Pool({
connectionString: "myconnectionstring",
});
const db = drizzle(pool, { schema: { ...schema, ...relations } });
import { drizzle } from 'drizzle-orm/neon-serverless'

const pool = new Pool({
connectionString: "myconnectionstring",
});
const db = drizzle(pool, { schema: { ...schema, ...relations } });
And I am very curious can the Terminating connection due to administrator command error be accounted for in this setup, thanks in advance. PS. connection string does NOT have -pooled at the end. Should it?
4 Replies
foreign-sapphire
foreign-sapphire12mo ago
Hmm. I cannot find any kind of "health-check" setting in drizzle or in node-postgres (what our serverless driver is based off of). The best idea I can think of is setting a idleTimeoutMillis option in the pool options. Maybe set it to 60000 milliseconds
complex-teal
complex-tealOP12mo ago
so I tried setting this to 2 minutes like this. But first, i have no confidence it makes any difference because the issue keeps happening. Second, it doesn't guarantee that neondb doesn't restart its compute at an arbitrary point in time. Third, when I try logging these 3 params of the pool
pool.idleCount
pool.totalCount
pool.waitingCount
pool.idleCount
pool.totalCount
pool.waitingCount
All of them show up as 0. So i'm not even sure how the pool object is working, as this is very strange behaviour, doesn't look like a native pg pool to me.
complex-teal
complex-tealOP12mo ago
No description
complex-teal
complex-tealOP12mo ago
I would rather be looking at "reconnectOnError" kind of thing rather than healthchecks, but i'm unclear where to look or if maybe there's examples on how to implement this yourself where you don't need to try catch every db operation. I imagine this is a problem everyone would face in any setup?

Did you find this page helpful?