There is a thread on pgsql-hackers mailing list, dating back to 1st of March 2020 about changes to Pg to optimize handling of larger number of connections.
The thread is pretty long, and the discussion took 5 months, but lately we got couple of commits:
- snapshot scalability: Don't compute global horizons while building snapshots.
- snapshot scalability: Move PGXACT->xmin back to PGPROC.
- snapshot scalability: Move PGXACT->vacuumFlags to ProcGlobal->vacuumFlags.
- snapshot scalability: Move subxact info to ProcGlobal, remove PGXACT.
- snapshot scalability: Introduce dense array of in-progress xids.
- snapshot scalability: cache snapshots using a xact completion counter.
- Fix race condition in snapshot caching when 2PC is used.
that (supposedly) should improve handling of large numbers of concurrent connections.
Unfortunately, I don't have ready test servers that would allow me to sensibly tests thousands of connections, but I think we can all safely assume that PostgreSQL 14 should handle large connection counts better than any PostgreSQL before. Thanks a lot, to all involved, but specifically to mastermind of this project: Andres Freund.