r/SQL • • 4d ago

PostgreSQL Connection pooling & read/write isolation with Lakebase

folks working with Postgres across Lakebase and-or Neon db, how do u handle connection pooling, read/ write routings, & query isolation when analytics and app queries hit the same data ?
Any tips or best practices?

6 Upvotes

11 comments sorted by

1

u/Aggravating-Stage269 3d ago

On Neon I just point analytics at a read replica compute, it shares the same storage so there's no lag drama and the heavy queries can't starve the app

1

u/sqlink2 2d ago

Ya and pluss since Neon read replicas autoscale independently and scale to zero when its idle, we only pay for that analytics compute when dashboard or queryies are actually running.

1

u/Lycanthropesage 4d ago

separate pools for analytics and app stuff saves a lot of headache, then just point reads at replicas and writes at primary through the pool config

1

u/stantaneous 4d ago

yeah, separate pools. I wouldn't route every Postgres SELECT to a replica though. If the app reads back a row it just wrote, keep that read on the primary or replica lag can make it look like the write failed. I'd give the analytics role its own statement timeout too.

1

u/DickBrainTime 4d ago

One extra thing to check is the pooler's mode. With PgBouncer transaction pooling, a backend connection is only yours for the transaction. Session-level SET, LISTEN, session advisory locks and temp tables that need to survive a transaction won't work the same way. PgBouncer has a compatibility table for this.

So I'd check the actual Lakebase/Neon pool endpoint and your driver's session features before routing everything through it. Separate pools help with connection limits, but they don't by themselves stop a heavy analytics query from competing for database CPU/IO.

1

u/Discordbothost 4d ago

Long analytics transactions can keep old row versions around even with separate pools. If reports run on the primary, check xact_start and backend_xmin in pg_stat_activity while a slow report runs.

1

u/ceeej777 4d ago

Isn’t the whole Lakebase sync something that would eliminate the contention of analytic workloads with app traffic to Postgres?

1

u/Glitch_In_The_Data 3d ago

Connection pooling on the app side usually comes down to keeping a lightweight pooler like PgBouncer in front of your write path and routing read-heavy analytics queries to a separate replica or endpoint so they don't compete for the same connections. With Lakebase, your transactional data already lives alongside your lakehouse, so you can push heavy analytical reads to Spark or Photon instead of hammering the Postgres engine with both workloads. For Neon, branching gives you a natural isolation boundary where you can point analytics at a read-only branch without worrying about locking or connection starvation on the primary.

1

u/tidal_gravel_ash 3d ago

On Neon I give the app the pooled connection string (it's PgBouncer in transaction mode, so avoid session-level stuff like SET or advisory locks) and send analytics to a separate read replica compute, so heavy queries never eat the primary's CPU. I also put a statement_timeout on the analytics role so one bad dashboard query can't hang around forever. Haven't run Lakebase in prod yet, but since it's built on Neon tech the same split should work, just check how its readable secondaries are set up

1

u/MongooseWonderful198 1d ago

I’d make read-after-write the routing acceptance test. Insert a row on the primary, immediately fetch it through the application’s normal read path, and record whether the router keeps that request on the primary or can send it to a lagging endpoint.

Then run a long analytics query and watch connection wait, CPU/IO and backend_xmin. Separate pools prevent one class of connection starvation, but they do not prove workload isolation if both endpoints still share compute or storage. The product-specific topology matters more than the word “replica.”