-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configurable role settings #2561
Comments
We could avoid the above config by instead doing ALTER ROLE anon SET pgrst.tx.statement_timeout = 500;
ALTER ROLE anon SET pgrst.tx.plan_filter.statement_cost_limit = 1000.0; Which would namespace our settings and make it clear that they only work through REST. Maybe also enable different settings per route ALTER ROLE anon SET pgrst.tx.projects.statement_timeout = 500; -- /projects path, unforunately we cannot use `/` inside a setting
ALTER ROLE anon SET pgrst.tx.clients.plan_filter.statement_cost_limit = 1000.0; -- /clients path Which reminds me of #2468, that could be done in the same way. ALTER ROLE anon SET pgrst.tx.projects.isolation = 'repeatable-read'; |
The problem here is that WITH
role_setting (database, setting) AS (
SELECT setdatabase,
unnest(setconfig)
FROM pg_catalog.pg_db_role_setting
WHERE setrole = CURRENT_USER::regrole::oid
AND setdatabase IN (0, (SELECT oid FROM pg_catalog.pg_database WHERE datname = CURRENT_CATALOG))
),
kv_settings (database, k, v) AS (
SELECT distinct on (k)
database,
substr(setting, 1, strpos(setting, '=') - 1) as k,
substr(setting, strpos(setting, '=') + 1) as v
FROM role_setting
ORDER BY k, database DESC
)
SELECT set_config(k, v, true)
FROM kv_settings; Something like this. This would allow to just do |
I think that query would be too expensive to run at the start of every transaction(would have to test it but it seems so, considering it's done for each request). Additionally it would not allow us to change the isolation as proposed above nor it would allow a per route setting. |
Not having a config for this definitely has some value though. Since we do the role switching ourselves users expect I still would like to cache these configs for perf though. Another option is to run the above query and get the settings for all the roles that are members of the connection role(authenticator) and cache the settings. They would get reloaded with This logic might later be useful for #2446 (comment) as well. |
Problem
Right now we can set
statement_timeout
at a global level, by setting a config on theauthenticator
role:This
statement_timeout
will be respected because GUC settings kick in at login time.However if we want to set different
statement_timeout
foranon
andweb_user
.These will not be picked up and their
statement_timeout
won't be enforced.Proposal
Query the settings specified on a config
These will be queried from
pg_db_role_setting
and then cached so we can doFor every transaction.
Further possiblities
This would allow us to integrate with other extensions, like https://github.com/pgexperts/pg_plan_filter. So we could say
And
plan_filter.statement_cost_limit
would be enforced for every transaction.This would solve #249
The text was updated successfully, but these errors were encountered: