I have frequent 500 errors due to exceeding number of connections to my DB.
This results in errors like this in /logs:
Job exception: FATAL: remaining connection slots are reserved for non-replication superuser connections
My config:
UNICORN_WORKERS: 12
UNICORN_SIDEKIQS: 2
DISCOURSE_DB_POOL: 90
My DB under load performs like this:
How can I optimize this? Please keep in mind the default config of PSQL has max connections limit set to 100.
I have plenty of RAM and CPUs for both web_data container and data container (which is hosted on a second server).
Update: I have a lot of open connections to DB from sidekiq, a lot more than it should (I have just 2 sidekiqs with 5 threads each).