frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

PgDog: Connection pooler, load balancer and sharder for PostgreSQL

1•levkk•1h ago
Hey HN!

Lev and Justin here, authors of PgDog (https://github.com/pgdogdev/pgdog), a connection pooler, load balancer and database sharder for PostgreSQL. If you build apps with a lot of traffic, you know the first thing to break is the database. We are solving this with a network proxy that doesn’t require application code changes or database migrations to work.

Our post from last year: https://news.ycombinator.com/item?id=44099187

The most important update: we are in production. Sharding is used a lot, with direct-to-shard queries (one shard per query) working pretty much all the time. Cross-shard (or multi-database) queries are still a work in progress, but we are making headway:

Aggregate functions like count(), min(), max(), avg(), stddev() and variance() are working, without refactoring the app. PgDog calculates the aggregate in-transit, while transparently rewriting queries to fetch any missing info. For example, multi-database average calculation requires a total count of rows to calculate the original sum. PgDog will add count() to the query, if it’s not there already, and remove it from the rows sent to the app.

Sorting and grouping works, including DISTINCT, if the columns(s) are referenced in the result. Over 10 data types are supported, like, timestamp(tz), all integers, varchar, etc.

Cross-shard writes, including schema changes (CREATE/DROP/ALTER), are now atomic and synchronized between all shards with two-phase commit. PgDog keeps track of the transaction state internally and will rollback the transaction if the first phase fails. You don’t need to monkeypatch your ORM to use this: PgDog will intercept the COMMIT statement and execute PREPARE TRANSACTION and COMMIT PREPARED instead.

Omnisharded tables, a.k.a replicated or mirrored (identical on all shards), support atomic reads and writes. That’s important since most databases can’t be completely sharded and will have some common data on all databases that has to be kept in-sync.

Multi-tuple inserts, e.g., INSERT INTO table_x VALUES ($1, $2), ($3, $4), are split by our query rewriter and distributed to their respective shards automatically. They are used by ORMs like Prisma, Sequelize, and others, so those now work without code changes too.

Sharding keys can be mutated. PgDog will intercept and rewrite the update statement into 3 queries, SELECT, INSERT, and DELETE, moving the row between shards. If you’re using Citus (for everyone else, Citus is a Postgres extension for sharding databases), this might be worth another look.

If you’re like us and prefer integers to UUIDs for your primary keys, we built a cross-shard unique sequence inside PgDog. It uses the system clock (and a couple other inputs), can be called like a Postgres function, and will automatically inject values into queries, so ORMs like ActiveRecord will continue to work out of the box. It’s monotonically increasing, just like a real Postgres sequence, and can generate up to 4 million numbers per second with a range of 69.73 years, so no need to migrate to UUIDv7 just yet.

    INSERT INTO my_table (id, created_at) VALUES (pgdog.unique_id(), now());
Resharding is now built-in. We can move gigabytes of tables per second, by parallelizing logical replication streams across replicas. This is really cool! Last time we tried this at Instacart, it took over two weeks to move 10 TB between two machines. Now, PgDog can do this in just a few hours, in big part thanks to the work of the core team that added support for logical replication slots to streaming replicas in Postgres 16.

Sharding hardly works without a good load balancer. PgDog can monitor replicas and move write traffic to a new primary during a failover. This works with managed Postgres, like RDS (incl. Aurora), Azure Pg, GCP Cloud SQL, etc., because it just polls each instance with “SELECT pg_is_in_recovery()”. Primary election is not supported yet, so if you’re self-hosting with Patroni, you should keep it around for now, but you don’t need to run HAProxy in front of the DBs anymore.

The load balancer is getting pretty smart and can handle edge cases like SELECT FOR UPDATE and CTEs with insert/update statements, but if you still prefer to handle your read/write separation in code, you can do that too with manual routing. This works by giving PgDog a hint at runtime: a connection parameter (-c pgdog.role=primary), SET statement, or a query comment. If you have multiple connection pools in your app, you can replace them with just one connection to PgDog instead. For multi-threaded Python/Ruby/Go apps, this helps by reducing memory usage, I/O and context switching overhead.

Speaking of connection pooling, PgDog can automatically rollback unfinished transactions and drain and re-sync partially sent queries, all in an effort to preserve connections to the database. If you’ve seen Postgres go to 100% CPU because of a connection storm caused by PgBouncer, this might be for you. Draining connections works by receiving and discarding rows from abandoned queries and sending a Sync message via the Postgres wire protocol, which clears the query context and returns the connection to a normal state.

PgDog is open source and welcomes contributions and feedback in any form. As always, all features are configurable and can be turned off/on, so should you choose to give it a try, you can do so at your own pace. Our docs (https://docs.pgdog.dev) should help too.

Thanks for reading and happy hacking!

Lev & Justin

ChatGPT's Translation Skills Parallel Most Human Translators

https://spectrum.ieee.org/chatgpt-translate-skills-human-comparison
1•pseudolus•47s ago•0 comments

The Broken Equilibrium

https://stackgen.com/blog/the-broken-equilibrium
1•darccio•1m ago•0 comments

Don't Trip[Wire] Yourself: Testing Error Recovery in Zig

https://mitchellh.com/writing/tripwire
1•PaulHoule•1m ago•0 comments

What evidence format helps technical diligence decisions move faster?

https://sot-navigator.com/
1•mthdadalto•1m ago•1 comments

phyz: Differentiable Physics Engine for Rust

https://phyz.dev
2•ecto•2m ago•0 comments

Why I don't think AI is a bubble

https://honnibal.dev/blog/ai-bubble
1•syllogism•2m ago•0 comments

AI Panic Hits Trucking, Transport Stocks

https://www.wsj.com/livecoverage/stock-market-today-dow-sp-500-nasdaq-02-12-2026/card/ai-panic-hi...
2•mattas•2m ago•0 comments

Paper, Scissors, Gravity

https://campedersen.com/phyz
1•ecto•3m ago•0 comments

Opinion: The Finance Industry Is a Grift. Let's Start Treating It That Way

https://www.nytimes.com/2026/02/06/opinion/capitalism-industry-financialization.html
3•cs702•3m ago•0 comments

You probably can't trust your password manager if it's compromised

https://www.theregister.com/2026/02/16/password_managers/
1•maguszin•3m ago•0 comments

Show HN: Lightweight tmux session and project manager written in Bash

https://github.com/rgcr/t-mux-manager
1•rgcr•3m ago•0 comments

Student

1•omarbouaziz•3m ago•0 comments

Gave Claude photographic memory for $0.0002/screenshot

https://github.com/deusXmachina-dev/memorylane
2•jzapletal•3m ago•1 comments

After Noam

https://justinpodur.substack.com/p/after-noam
1•hackandthink•4m ago•0 comments

IBM tripling down on hiring new grads

https://techcrunch.com/2026/02/12/ibm-will-hire-your-entry-level-talent-in-the-age-of-ai/
1•alirohde•4m ago•1 comments

Focus Better with a Dressing Table with Mirror and Lights

https://dreamhomestore.co.uk/collections/dressing-tables
1•millie2conroy•4m ago•1 comments

A C compiler in TypeScript, Written by Claude

https://github.com/Rajeev-K/c-compiler
1•rajeev-k•5m ago•0 comments

Show HN: Quackback – Open-source customer feedback your AI agent can triage

https://github.com/QuackbackIO/quackback
1•mortondev•6m ago•1 comments

Three Sketches of ASL-4 Safety Case Components

https://alignment.anthropic.com/2024/safety-cases/
1•consumer451•8m ago•0 comments

Use skills smarter with SkillDock's CLI manager

https://skilldock.io/skill/skilldock/skilldock-cli-usage
1•eugeneevstafev•9m ago•0 comments

Index, Count, Offset, Size

https://tigerbeetle.com/blog/2026-02-16-index-count-offset-size/
2•cyndunlop•9m ago•0 comments

I taught LLMs to play Magic: The Gathering against each other

https://mage-bench.com/
1•GregorStocks•10m ago•1 comments

Gentoo Takes the First Step to Ditch Microsoft Copilot-Infested GitHub

https://itsfoss.com/news/gentoo-github-switch-begins/
1•abdelhousni•10m ago•0 comments

I've Created Modular Open Source Shelters

https://thios.co/en/
1•pete-thios•10m ago•1 comments

StewReads – Turn Claude chats into Kindle ebooks

https://ankitgupta.dev/blog/building-stewreads
2•rajma•11m ago•1 comments

The Cloud Above the Clouds

https://subreply.com/reply/30957
1•lucianmarin•12m ago•0 comments

Metadata Is Not Understanding: Knowledge Graph Version Control for AI Code

https://hub.controlvector.io/blog/metadata-is-not-understanding
2•jwschmo218•13m ago•1 comments

Show HN: Deathwink – Send messages to people after you die

https://deathwink.com
1•randallme•14m ago•1 comments

Mac is now a gaming PC

https://xcancel.com/mygamesir/status/2022959064632938560
1•frizlab•14m ago•1 comments

Why Europe doesn't have a Tesla

https://worksinprogress.co/issue/why-europe-doesnt-have-a-tesla/
1•ortegaygasset•15m ago•0 comments