-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
community[patch]: Allow using a pool for PostgresRecordManager #4409
base: main
Are you sure you want to change the base?
Conversation
Enable to use a predefined pool for PostgresRecordManager, allowing to use multiple indices per database. Without, each index will create a new pool, leading to Postgres connection exhaustion.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mkesper , thanks for adding this, great thinking! Left a couple of comments (not a maintainer, wrote the original implementation)
this.namespace = namespace; | ||
this.pool = new pg.Pool(postgresConnectionOptions); | ||
if (pool instanceof Pool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
violates eslint rule. checking that pool is not undefined should be fine
} else { | ||
try { | ||
this.pool = new pg.Pool(postgresConnectionOptions); | ||
} catch (err: unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pool constructor does not throw when config is undefined/invalid as far as I can tell. checking that pool and config aren't both undefined should work
@MJDeligan Thanks, you're right, that code could be improved. :) Since I posted I'm not anymore sure what's the best way to handle the problem that connections are held for a long time. Could also be a problem in the code calling the RecordManager not closing it. (A hint for that in the examples would be really nice). |
@mkesper I think you're right that having multiple pools will lead to the creation of too many clients. Being able to pass your own pool is definitely good. Not ending the pool(s) will of course worsen this. Sorry about the documentation, the long example is a little unwieldy. Maybe a very minimal example at the beginning would be good to add. |
Thank you for the review @MJDeligan! I think technically the instanceof check is ok here (with a linter ignore) because it's Node only. Have seen instanceof checks be unreliable in environments that use bundlers like Next.js since you can wind up with multiple declarations in different chunks. But probably best to avoid yes. |
Enable to use a predefined pool for PostgresRecordManager, allowing to use multiple indices per database. Without, each index will create a new pool, leading to Postgres connection exhaustion.
Fixes #4407