Skip to content

[RFC 0001] Connection Pooling #33

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

Merged
merged 1 commit into from
Jul 26, 2021
Merged

[RFC 0001] Connection Pooling #33

merged 1 commit into from
Jul 26, 2021

Conversation

kiwicopple
Copy link
Member

We would like to explore connection pooling on Supabase. This RFC is intended to decide:

  • Whether we should provide a pooler
  • Which connection pooler we should use
  • Where in the stack it would be installed - i.e. if should bundle it with the Postgres build

Rendered


### 1. Decide on a PG Pooler

- `pg_bouncer` - https://www.pgbouncer.org/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also an AWS pgbouncer fork: https://github.com/awslabs/pgbouncer-rr-patch.


In Postgres, every connection is a process. Because of this, a lot of connections to the database can be very expensive on memory.

When connecting to Postgres database from serverless functions, there is no connection pooling, and so the server needs to maintain hundreds/thousands of connections.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transaction pooling and statement pooling(see pgbouncer types of pooling) might help there. The disadvantage of those is that they cannot use prepared statements for example, so we'd need to check for support on common client libs(too much work, maybe just document it).

Seems DO also recommends transaction pooling: https://assets.digitalocean.com/articles/managed_db_pools/connection_pool_blank.png

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on this - when I look at the additional tooling around Postgres, pgbouncer seems to be the one supported most frequently (eg, pgmetrics, various postgres operators).

[drawbacks]: #drawbacks

- Security
- Not directly relevant to the "supabase" stack, so it's additional non-core support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a dedicated GitHub discussion category for "External libraries" and mention it's low prio for us(plus reasoning).

@dragarcia dragarcia self-assigned this Mar 13, 2021
@dragarcia
Copy link
Contributor

Will merge this in for future reference.

@dragarcia dragarcia merged commit f98cbfa into develop Jul 26, 2021
@dragarcia dragarcia deleted the rfc/connection_pooling branch July 26, 2021 08:04
damonrand pushed a commit to cepro/postgres that referenced this pull request Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants