snippetsqlModerate
How to set statement timeout per user?
Viewed 0 times
perstatementusertimeouthowset
Problem
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?
Eg: Guest 5 minutes and Admin 10 minutes.
Is it possible in Postgres 11.11?
Solution
Yes, Postgres allows settings per user or even per database and user, including
Related:
To see the currently active setting for the session:
Or get more details from the view
To check current settings for a role:
statement_timeout:ALTER ROLE foo SET statement_timeout = 12345; -- millisecondsRelated:
- How does the search_path influence identifier resolution and the “current schema”
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';Code Snippets
ALTER ROLE foo SET statement_timeout = 12345; -- millisecondsSHOW statement_timeout;SELECT *
FROM pg_settings
WHERE name = 'statement_timeout';SELECT rolname, rolconfig
FROM pg_roles
WHERE rolname = 'foo';SELECT rolname, unnest(rolconfig) AS setting
FROM pg_roles
WHERE rolname = 'foo';Context
StackExchange Database Administrators Q#290714, answer score: 15
Revisions (0)
No revisions yet.