1500 connection limit? π
I have double your active users running on under 30 direct postgres connections most of the time. WEB_CONCURRENCY=24 and MAX_THREADS=15 (this is specific to my 44 CPU core count, don't overdo it...)
This might be over-explaining, but this is my setup:
1. You need to install pgBouncer
Scaling up your server - Mastodon documentation
I have max_client_conn = 10000 and default_pool_size = 30 and reserve_pool_size = 120 set in pgbouncer.ini
This allows practically unlimited connections from Mastodon, but only 30 will be opened with postgres. It will scale up to 150 if absolutely required but that very rarely ever happens.
2. You should set max connections in Postgres itself to 300 and check
PGTune - calculate configuration for PostgreSQL based on the maximum performance for a given hardware configuration
PgTune - Tuning PostgreSQL config by your hardware
again.
Use OLTP instead of Web as the DB type. If your DB is on the same server as Mastodon don't just enter your total core count and RAM, enter only what you want dedicated to Postgres (so... probably about half).
Some settings depend on what max connections is, so if you ran pgTune before and then increased it they're probably wrong, best to double-check them all.
3. Profit