Skip to content
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

[Bug]: Postgres Idle Connections #30197

Open
1 task done
sneha122 opened this issue Jan 10, 2024 · 5 comments
Open
1 task done

[Bug]: Postgres Idle Connections #30197

sneha122 opened this issue Jan 10, 2024 · 5 comments
Assignees
Labels
Bug Something isn't working High effort More than a sprint Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage Postgres Postgres related issues Production Query & JS Pod Issues related to the query & JS Pod

Comments

@sneha122
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Description

When a cloud user executes PostgreSQL queries at page start, it creates new sessions. However, these sessions don't close after the page is closed or are no longer needed. This causes the sessions to accumulate and quickly hit the 100-session limit they have set in their database

Steps To Reproduce

https://theappsmith.slack.com/archives/C0341RERY4R/p1703228974015659

Public Sample App

No response

Environment

Production

Issue video log

No response

Version

Cloud/ Self-Hosted - 1.8.4

@sneha122 sneha122 added Bug Something isn't working Needs Triaging Needs attention from maintainers to triage Postgres Postgres related issues labels Jan 10, 2024
@sneha122 sneha122 self-assigned this Jan 10, 2024
@github-actions github-actions bot added the Integrations Product Issues related to a specific integration label Jan 10, 2024
@sneha122
Copy link
Contributor Author

Checked out this user issue with respect to postgres idle connections, there are a couple of things unknown right now, because of which I was not able to reproduce the issue, we have asked for this information from the user, the conversation is going on here. We have asked user for details like:

  1. Where they have hosted their postgres DB. This information is crucial because we know from past experience that when we create a postgres DB on supabase, it creates issues with connection pool and causes idle connections to be created. If we get to know where user has hosted their DB it would help us reproduce the issue quickly
  2. Whether user has created one datasource or multiple datasources against the same DB. This can be useful in understanding why multiple connections are being created

Apart from this, I checked out the connection pool codebase and also the logs when multiple connections are created, here are a couple of observations:

  1. When we execute a query, we check if the datasource context already exists or not, if it does we use the same to execute the query and hence no new connection is created. In case the context does not exist, we create a new connection and add that connection in the pool.
Screenshot 2024-01-11 at 10 59 22 AM Screenshot 2024-01-11 at 10 59 37 AM 2. We also check if the connection in the pool is stale, we destroy that connection, but the way in which we determine if connection is stale or not is by checking the timestamp of when the datasource object was updated and when the datasource context was created. In our situation when we execute select queries, datasource object is never updated, hence the context will never become stale and will remain in the pool Screenshot 2024-01-11 at 11 00 06 AM Screenshot 2024-01-11 at 11 00 15 AM 3. I also checked the cloud logs when the active connections to database keep increasing, the entry point in our code base for creating new connection for postgres is as shown below. When searched in logs for "Connecting to Postgres db", I could not find any results, which either means that these active connections are not happening from our code base or there is another entry point for creation of these connections. Screenshot 2024-01-11 at 10 59 37 AM

@sneha122
Copy link
Contributor Author

Moving this issue back to sprint backlog, we can further investigate this issue once we have required information from user.

@github-actions github-actions bot added the Query & JS Pod Issues related to the query & JS Pod label Mar 2, 2024
@Nikhil-Nandagopal Nikhil-Nandagopal added the Critical This issue needs immediate attention. Drop everything else label Mar 4, 2024
@rohan-arthur rohan-arthur removed the Critical This issue needs immediate attention. Drop everything else label Mar 5, 2024
@rohan-arthur rohan-arthur added the High effort More than a sprint label Apr 1, 2024
@rhuanbarreto
Copy link

I'm also having this issue.

@habermst
Copy link

habermst commented Oct 28, 2024

Same issue. Using am Postgres installed on a azure vm. Asked on Discord. Here is the screenshot:
image
Some more context:

Row Count shows the idle connections (this was taken after about 1.5 - 2 hrs). Only one user (me) actively working on an app & testing. SET application_name = 'Appsmith JDC Driver' has 47 idle connections. The other one with 36 connections was executed when a modal was opened for a spefic id. So I would expect it to reuse the connection. Apart from the param, it was the exact same statement.

@rhuanbarreto
Copy link

Best solution today is to use pgbouncer to try to minimize. But appsmith itself could also improve this on their side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working High effort More than a sprint Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage Postgres Postgres related issues Production Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

No branches or pull requests

5 participants