Just use <a href="https://github.com/yandex/odyssey" rel="nofollow">https://github.com/yandex/odyssey</a> :) It's a scalable PgBouncer.
We started with the most battle-tested and native option to Postgres, which is PgBouncer and tried tuning it the right way. Also now that long due kinks like support for prepared statements are solved, it’s been working really well. There are many customers scaling well with 10K+ Postgres connections. We will consider other options like odyssey, pgdog in the future!<p>Side note: I’m not a big fan of having 10K+ connections on Postgres, 100s are more than enough to scale Postgres well. But that’s a story for another day. ;)
> 100s are more than enough to scale Postgres well<p>I'd want to know what the workload is. That's true of lots of projects, especially internal tools (even for multinationals). But for my last project, that would have been tough. And by FAANG standards my last project was 'medium' sized, even though it was large by the standards of many places I've worked.<p>(The galling thing is I shrunk the hardware by 40% but if I'd been there during the architecture phase I'm pretty sure I could have shrunk it by 8x by solving a completely different problem that had higher margins than what we actually did)
Fun (semi-related) fact, ClickHouse was originally developed by Yandex :)
yandex is a russian company, so no, don't use it
I have bad news for you about where ClickHouse comes from then.
Do you boycott American companies too? I'm assuming you boycott Russian companies because Russia causes death and destruction. But the USA caused much more death and destruction than Russia ever did - do you boycott them too?
uhhhh
Cool, another whataboutism. USA caused a lot of damage, but USA is a grey country - they do a lot of bad things but they also do a lot of good things (science & technology).<p>russia is one-dimensional and that dimension is violence. They don't invent things, they don't innovate, they don't export anything (apart from gas/minerals) and they only have imperialistic ambitions.
Objectively speaking, Russia is one of the most creative and innovative societies of all time. Literature, science, music, sporting, mathematics, computing, you name it, a Russian has innovated in it.
except for perhaps… a scalable pg bouncer? And good nuclear reactors [1]?<p>Not to say I support many Russian political moves, but I think discrediting an entire people and their outputs on Russian politics is brusque - particularly open source ones.<p>[1]: <a href="https://www.abc.net.au/news/2026-05-08/russia-nuclear-power-diplomacy-and-dependence/106647598" rel="nofollow">https://www.abc.net.au/news/2026-05-08/russia-nuclear-power-...</a>
nginx is also Russian, so don't use... a third of the web.
thank you for the advice mr mcarthy, i'll happily use deepseek and GLM to vibe my next project.
> The cancel lands on a process that has never heard of the query, and nothing happens.<p>> Peering fixes this. The processes are aware of one another, so a cancel that lands on the wrong process is forwarded to the one that actually owns the session.<p>I understand "peering" as a concept here but have never tried this with PostgreSQL before. May I ask:<p>A) Does PostgreSQL have a mode/setting for peering that makes this easy? I'm imagining a mechanism that either goes round robin (re-sending the cancel to peers until it doesn't return an error of some kind) or some metadata in the cancel request that enables the wrong-destination process to somehow identify the proper process.<p>B) And by what mechanism? If all the PostgreSQL processes are listening to clients via so_reuseport, I guess there must be some other IPC method used for the peering chatter.
AI clearly wrote TFA. The cancellation thing is apparently a PgBouncer feature - the peering is between bouncer processes, not server processes. It sounds like it should be easy enough to make the bouncer process ID part of the cancel key.
you encode information in the token, this was a motivation for postgres to remove 32 byte cap on tokens: <a href="https://www.postgresql.org/message-id/508d0505-8b7a-4864-a681-e7e5edfe32aa@iki.fi" rel="nofollow">https://www.postgresql.org/message-id/508d0505-8b7a-4864-a68...</a><p>See from slide 26 <a href="https://www.pgevents.ca/events/pgconfdev2024/sessions/session/107/slides/48/2024-05-29-the-postgres-protocol%20(split).pdf" rel="nofollow">https://www.pgevents.ca/events/pgconfdev2024/sessions/sessio...</a>
Jelte's a pgbouncer maintainer, video of a talk on this by him: <a href="https://www.youtube.com/watch?v=X-nCHcZ6vQU" rel="nofollow">https://www.youtube.com/watch?v=X-nCHcZ6vQU</a>
Interesting. We run pgbouncer via kubernetes so it was straightforward to make multiple pgbouncer processes on one machine. Also straightforward to get them running on multiple machines, which helps because we run on Azure and they like to cause rolling outages across our fleet via VM maintenance...
I've been using pgdog (<a href="https://github.com/pgdogdev/pgdog" rel="nofollow">https://github.com/pgdogdev/pgdog</a>) and it has worked really well for my needs!
Glad you like it. It was built to fix some of PgBouncers shortcomings that we ran into at Instacart many years ago, and to have a stronger foundation for scaling Postgres horizontally (that's sharding)!
Ack, we will consider offering pgdog in the future! More context on why we chose pgbouncer <a href="https://news.ycombinator.com/item?id=48873867">https://news.ycombinator.com/item?id=48873867</a>
It's been a pong pong back and forth between PG reverse proxy submissions lately! "Why we built [Pgdog]":
<a href="https://news.ycombinator.com/item?id=48819308">https://news.ycombinator.com/item?id=48819308</a>
can it work in kubernetes with peering? since there won't be any need to reuse ports there. or separate pods will have separate pools and will act as independent?
First time I've heard of so_reuseport, which is interesting. The important parts of the setup seem to be that + peering; is peering built-in to PgBouncer and simple to set up?
I'm 46 now. I remember being shocked at Postgres's heavy connection model when I was 23.<p>I gather things haven't improved since?
It improved quite a lot! It scales pretty well to thousands of connections: <a href="https://techcommunity.microsoft.com/blog/adforpostgresql/improving-postgres-connection-scalability-snapshots/1806462" rel="nofollow">https://techcommunity.microsoft.com/blog/adforpostgresql/imp...</a>.<p>However, if pooling isn’t used, there’s always an overhead (tens of milliseconds or more) when creating a new connection because Postgres needs to fork a process. And yes, applications can be written without pooling, which isn’t ideal, but happens quite a lot.<p>Application frameworks have also changed. Serverless architectures can generate tens of thousands of connections, which is where Postgres starts to run into issues. I’m personally not a big fan of using more than a few hundred connections, but it is very realistic in this era.
You were coming into the field just as companies were fielding their first reasonable answers to the Threading Model that Java put forward, which was sort of Windows' but with extra features. Even Solaris choked on Java. HP UX did worse and I can't recall if SGI was worse or better than HP. But getting compatible with Java shook a lot of companies up, in how they handled concurrency.<p>Postgres and SQLite were being designed at that same time but by industry veterans. People who had been deploying high load systems before any of this threading nonsense was around. And they were supporting people running on old hardware.
Was there a disadvantage to using HAProxy + multiple PGBouncer instances?
This was more for fun than real use, but I greatly enjoyed hacking something similar into rqbit bittorrent client.
I wanted to run an instance of 'rqbit download' per torrent via so_reuseport. When a peer tries to connect, it gets sent to a random instance. So I built a whole rendezvous system, where instances find each other & either proxy data to each other or fd pass the socket to each other directly to get the peer socket to the instance that needs it. It uses postcard rpc to chat between instances.<p>Clickhouse's so_reuseport rendezvous needs are obviously for a very different, but fun to see some so_reuseport coordination like this (for a much more practical use)!<p>It'd be really neat to have some kind of general peering protocol that different apps could use. This whole exercise was gratuitous as heck for my application, I don't even really intend to use this, but it was a fun path to walk down. So I don't really know what the broader protocol would really be for, what we would use it for. But it seems like such a cool idea! A shared Turso database would probably be a bit more practical than the rpc system, honestly. Ha.<p><a href="https://github.com/rektide/rqbit/tree/peering" rel="nofollow">https://github.com/rektide/rqbit/tree/peering</a>
Article should show the config:<p>[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 6432
so_reuseport = 1
peer_id = 1
unix_socket_dir = /tmp/pgbouncer1<p>[peers]
1 = host=/tmp/pgbouncer1
2 = host=/tmp/pgbouncer2
3 = host=/tmp/pgbouncer3
4 = host=/tmp/pgbouncer4