0

Let's say I have a role called user1, user2 and postgres.

Is it possible to alter the default privileges while logged in as postgres for objects created by user1 so that user2 can see them?

This is what I currently have, but this only works if I'm logged in as user1:

alter default privileges grant usage on schemas to user2;
alter default privileges grant select on tables to user2;
alter default privileges grant usage, select on sequences to user2;

Is it possible to get this to work while logged in as postgres?

1 Answer 1

1

To add default privileges for a different user, use the FOR ROLE clause:

ALTER DEFAULT PRIVILEGES FOR ROLE user1 ...

See the documentation for details.

As to the required permissions to run that statement, the documentation says:

You can change default privileges only for objects that will be created by yourself or by roles that you are a member of.

That means that, unless you are a superuser, you can only use roles in FOR ROLE of which you are directly or indirectly a member.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.