I have a website up and running but keep getting “OperationalError“ in Sentry. I have read the Heroku documentation and it seem that configuring a PGBouncer would help me a lot.
pgbouncer in transaction-pooling mode allows you to have thousands of clients run queries against your database. It comes with a trade-off though: you can’t use postgres features tied to sessions/connections.
One of those features you can’t use, and a common pgbouncer+django gotcha, is server side cursors, which is Django’s default behavior. You’ll need to disable that: Settings | Django documentation | Django
There can still be limits though. Pgbouncer and Postgres both have settings for max allowed connections. You’ll need to make sure both pgbouncer is configured to to use fewer than your Postgres’s max connections, and you need to make sure you’ve configured pgbouncer to allow enough connections for your application.
pgbouncer can handle 5k, 10k, maybe more connections. It is single threaded, so you can check to see its CPU utilization and if you’re still using less than a core you may be able to push up its max connections higher.