how to create duplicate role of a user in postgres

UserBSS1 picture UserBSS1 · May 16, 2013 · Viewed 19.6k times · Source

I need a new user but it should be granted all those privileges that the other existing user/role has.

e.g.

  • User A has SELECT privileges on Table1
  • User A has EXECUTE privileges on Table2
  • ...

If a new User B is created, I need the same privileges as,

  • User B has SELECT privileges on Table1
  • User B has EXECUTE privileges on Table2
  • ...

Dont ask why :/

Actually User A has custom privileges on different tables, schemas, and functions; so its very tedious and lengthy process to manually grant permissions to the new user. Any help would be good.

Answer

Igor Romanchenko picture Igor Romanchenko · May 16, 2013

Try something like:

GRANT A TO B;

It will grant all right of role A to B.

For details read this chapter of the manual.