-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to stop connections from closing when idle #699
Comments
@vitaly-t thanks. I am using the methods that automatically connect. should this already work? |
Yes, it should just work. Not sure why would your connection be not reused. |
the connection is being reused as long as I keep hitting my endpoint without waiting too long (I see useCount increase every time). let me run some more tests and I will get back to you. |
@vitaly-t i enabled connection logs on my pg instance (which is a helm package installed in my local kubernetes cluster using stable/postgresql) and this is some of what i'm seeing:
all connections end after around 10 seconds of inactivity. the pg conf is pretty much what comes out of the box. |
ok, i figured it out. import pgpLib from 'pg-promise';
const pgp = pgpLib();
const db = pgp({
connectionString: process.env.DB_URL as string,
idleTimeoutMillis: 0,
}); |
This looks like a bug in the driver then. But then again, overriding defaults isn't the standard way of doing it, it should be all in the connection: const db = pgp({
connectionString: process.env.DB_URL as string,
idleTimeoutMillis: 0,
max: 20
}); My advise - do not do any overrides in the defaults. |
ok, I have fixed my problem. should this issue be closed or what do you prefer? I feel like there is not enough documentation regarding this. |
You can log this issue against the driver, but here, there is nothing we can do, except use it through connection details, as I suggested. And I'm going to update the connection page now. |
@rhyek I have thoroughly updated the Connection Syntax page ;) |
Expected behavior
For my setup, I want database connections to remain idle forever
Actual behavior
In a small local setup, hitting my database via a restful api will take around 2s after some amount of idle time. Using pg-monitor, I can see
useCount === 0
every time this happens. After this, every subsequent request will respond in 10ms or less anduseCount
will increment.I have tried the following to no effect:
For my setup, I want database connections to remain idle forever until they're needed to avoid this new connection overhead. Could someone please provide code example of how to achieve this? Thanks.
Environment
The text was updated successfully, but these errors were encountered: