As an example, if I have 3 users in Postgres, lets call them user_a, user_b, user_c… How can I ensure that they cannot hold more than two open connections at the same time? I may also have a user called user_z, and I would be happy to have them hold over 100+ connections. So limiting the overall number of connections in the db is not an option.
I looked into connection limit inheritance for roles but I cannot seem to find a clear answer on if this is the right path to go down.
2
Answers
You can create roles, give each role its own connection limit, and then assign the users appropriately.
The best I can think of is an event trigger that triggers on
login
, checks the currently active sessions and throws aFATAL
error if the quota is exceeded. That is not an elegant solution, but then the requirement is quite unusual.