PostgreSQL – Query Resource Quota for Accounts

postgresql

Within the latest (12, 13) versions of PostgreSQL, is there any throttling support on the user-account level, to limit how much data any query can produce and/or how much time + memory it may consume under that user account?

I want to limit specific user accounts to allow up to certain amount of data and/or time to consume within the server, before erroring with "query quota exceeded" or something like that.

Example

I want to configure user account guest to produce "quota exceeded" failure for any query that returns more than 10kb of data or takes more than 10 seconds to execute.

Best Answer

There is no support for resource quotas in PostgreSQL.

Your best bet is statement_timeout:

ALTER ROLE baduser SET statement_timeout = '10s';

You cannot limit the number of rows returned, but perhaps statement_timeout is good enough.