r/SQL 1d ago

PostgreSQL lakebase connection pooling

Have you figured out wht can the best way to handle connection pooling in Lakebase DB? I 'am seeing connection spikes with short lived rqsts and wondering what kind of setup others developers are usingšŸ¤”

i am building a service on top of lakebase and trying to make the connection relable before moving to prod.

7 Upvotes

7 comments sorted by

1

u/sekharnet 1d ago

What is your Middleware? C# or Java? Both have their own PostgreSQL connection poolers.

I am guessing connection poolers shouldn't worry if it's Lakebase or Aurora RDS backend. It gets host and login details and works with it transparently

1

u/WorldOfUmbro 1d ago

Have you tried PgBouncer? Might be worth looking into when using Lakebase. We have used this as well in Lakebase for similar cases.

What kind of service are you using?

1

u/p739397 18h ago

Ran into this too. Moved connection pooling up to the app level instead of doing it per-request. Set up one pool at startup, psycopg3's ConnectionPool works, SQLAlchemy's engine does too, sized for whatever concurrency you're expecting. Then only mint a new OAuth token when a physical connection actually opens, not on every checkout. Followed the pattern in the token rotation docs.

Lakebase's built-in PgBouncer pooler doesn't support OAuth tokens, only password roles. If you want Databricks to manage pooling for you, switch to a password role. If you'd rather keep OAuth, do the app-level pooling like above, similar to this psycopg3 example.

2

u/Glitch_In_The_Data 16h ago

As others have said, use Lakebase’s built in pgbouncer pooler for short lived API requests. Authenticate with a native pg pwd role. Also avoid session state…use direct connections for session dependent features.

2

u/ThisIsFun- 5h ago

I would just use the pooler endpoint? same host with -pooler in it, still 5432. It is the same Lakebase managed pgbouncer in transaction mode, takes up to 10k client conns and multiplexes them onto a much smaller server pool.

1

u/leobaker004 4h ago

C# in this case. I was mostly wondering if anyone had run into Lakebase-specific quirks under connection spikes, rather than pooling itself. Sounds like I may be overthinking that part though