Search code examples
mysqldatabasepostgresqlquota

Is there a way or technology to implement database resource allocation based on user?


Typically, when platforms want to provide database resource to user (developer) for applications development, they use limit database access APIs to restrict behaviors of the application, in order to enforce some constraints on resources occupied, an example is social API.

Is there a same way that we can implement and use in database layer, nor application layer. If then, we just need to assign database quota for specific user and let database handle the resource usage. Furthermore, it's better to have some programming APIs from database server to support this.

I found some similar questions, as follow:

Since i am focus on open source solutions, how about PostgreSQL or NoSQL? As open source database, I think PostgreSQL compares better favourably with Oracle.


Solution

  • With MySQL (which is currently released under the open source GPL license), you can impose the following resource limits inside the database:

    The number of queries that an account can issue per hour

    The number of updates that an account can issue per hour

    The number of times an account can connect to the server per hour

    The number of simultaneous connections to the server by an account

    For postgres, their wiki states:

    PostgreSQL has no facilities to limit what resources a particular user, query, or database consumes, or correspondingly to set priorities such that one user/query/database gets more resources than others. It's necessary to use operating system facilities to achieve what limited prioritization is possible.

    But the question to me really is -- no matter which database is used -- what is the expectation when a user exceeds their limits? If the database enforces limits, should queries beyond those limits simply return an error and cause the application to fail? I'd suspect that this might have unexpected negative impacts on the applications. It's hard to say what will happen when suddenly the database starts returning errors.