All we need is an easy explanation of the problem, so here it is.
I have multiple users in Postgres. I would like to set up different statement timeouts for different users.
Eg: Guest 5 minutes and Admin 10 minutes.
Is it possible in Postgres 11.11?
How to solve :
Yes, Postgres allows settings per user or even per database and user, including
ALTER ROLE foo SET statement_timeout = 12345; -- milliseconds
To see the currently active setting for the session:
Or get more details from the view
pg_settings (including how it was set):
SELECT * FROM pg_settings WHERE name = 'statement_timeout';
To check current settings for a role:
SELECT rolname, rolconfig FROM pg_roles WHERE rolname = 'foo';
rolconfig is an array, unnest it to get one setting per row:
SELECT rolname, unnest(rolconfig) AS setting FROM pg_roles WHERE rolname = 'foo';
Found that we can set the timeout on Role.
ALTER ROLE guest SET statement_timeout='5m'; ALTER ROLE admin SET statement_timeout='10m';
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂