Common max replica on multiple HPA scaled deployments

I have deployments consuming different RabbitMQ queues. Each deployment has a different HPA tied to the queue metrics with different scaling formulas.
All of this works well.

The pods write into a DB and I would like to have the total number of pods for all deployments limited to a number to avoid overloading the DB.

I didn’t find a way to do this.
I tried tweaking the metric formula to include a max based on the pod count of the other deployments but it’s not very reliable. The lag of the metrics causes scaling up and down. I’m pretty sure it’s not the correct way.
Any other idea?