I have several tables in Postgres 9.2.23 that I need to update privileges on regularly (daily or multiple times per day). I have a master list maintained elsewhere of who can select that I use to grant privileges. However, I want to make sure that anyone who used to be on the list but has dropped off has all their privileges revoked.
My thought was to do a clean sweep with something like:
revoke all privileges on my_table from [all users/roles]
before I grant select to the authorized users. However, I have not been able to figure out how to do a bulk revoke on all users/roles like that.
I know I can generate a list of users/roles that currently have privileges and go from there, but I am hoping there is a shortcut to bypass this.
There is a canonical answer to this provided by postgres documentation - also related to this post. I had to do a lot of trial and error myself to understand why there isn't a simple
REVOKE ALL FROM role
solution and the reason comes down to the answer:The reason (or so I have gathered) why this is the solution and you cannot just revoke all permissions, is that the "doomed_role" may be the owner of some entities and therefore they need to be reassigned first before revoking their permissions. So long as you do these commands in this order, it will do what you need to do.