The PostgreSQL superuser
In this recipe, you will learn how to grant the right to a user to become a superuser.
A PostgreSQL superuser is a user that bypasses all permission checks, except the right to log in. This is a dangerous privilege and should not be used carelessly. Many cloud databases do not allow this level of privilege to be granted. It is normal to place strict controls on users of this type.
How to do it…
Follow the steps to add or remove superuser privileges for any user:
- A user becomes a superuser when it is created with the
SUPERUSER
attribute set:
CREATE USER username SUPERUSER;
- A user can be deprived of its superuser status by removing the
SUPERUSER
attribute using this command:
ALTER USER username NOSUPERUSER;
- A user can be restored to superuser status later using the following command:
ALTER USER username SUPERUSER;
- When neither
SUPERUSER
norNOSUPERUSER
is given in theCREATE USER
command, then the default is to create a user who is not a superuser.
How it works…
The rights to...