In this article we are going to cover how to upgrade a user to be a superuser in PostgreSQL. In PostgreSQL there is a unique term “role”, the term “role” will be discussed later because it’s a complicated feature by itself.
TL;DR: ALTER USER username WITH SUPERUSER;
Upgrade a User to be a Superuser
In PostgreSQL ALTER USER the statement we use to alter a user’s grants and properties. You can learn more about ALTER USER statement from this link.
postgres=# ALTER USER testuser WITH SUPERUSER;
ALTER ROLE
Also reverting is possible:
postgres=# ALTER USER testuser WITH NOSUPERUSER;
ALTER ROLE
Use Case
You can alter a user with superuser grants now, but we haven’t talk about use case of this statement and where to use it. After creating a user, if we need global administration features on a user we can update a user to be a superuser. We also, can, revoke superuser privileges back with same statement.



Leave a Reply