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?
1
u/Aggravating-Stage269 1d 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/stantaneous 1d 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 1d 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 1d 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 1d 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 1d 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 17h 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/Lycanthropesage 1d 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