8

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?

Erwin Brandstetter
  • 185,527
  • 28
  • 463
  • 633
Dharanidhar Reddy
  • 193
  • 1
  • 1
  • 7

2 Answers2

16

Yes, Postgres allows settings per user or even per database and user, including statement_timeout:

ALTER ROLE foo SET statement_timeout = 12345;  -- milliseconds

Related:

To see the currently active setting for the session:

SHOW statement_timeout;

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';
Erwin Brandstetter
  • 185,527
  • 28
  • 463
  • 633
1

Found that we can set the timeout on Role.

ALTER ROLE guest SET statement_timeout='5min';
ALTER ROLE admin SET statement_timeout='10min';
Dharanidhar Reddy
  • 193
  • 1
  • 1
  • 7