Change a Database User’s SuperUser Status

A database superuser bypasses all permission checks, except the right to log in.

This is a dangerous privilege and should not be used carelessly; it is best to do most of your work as a role that is not a superuser.

That being said, you might want to allow a particular database user to become a superuser for certain activities – like running tests in a development enviroment.   

Here’s how to how to change a user to superuser in YugabyteDB.

				
					yugabyte=# SELECT usename, usesuper FROM pg_user ORDER BY 1;
     usename     | usesuper
-----------------+----------
 postgres        | f
 postgres_user   | f
 postgresql_user | t
 yugabyte        | f
(4 rows)
				
			

I want to change the user yugabyte to be a superuser, but I can only do that logged into the database as a current superuser. On my database, only the postgresql_user is a superuser, so I will need to log on as it.

				
					yugabyte=# \q

[root@localhost ~]# ysqlsh -h xxx.xx.xx.xxx -U postgresql_user;
ysqlsh (11.2-YB-2.15.2.0-b0)
Type "help" for help.

yugabyte=# SELECT user;
      user
-----------------
 postgresql_user
(1 row)
				
			

Now that I am logged in to the database as the superuser postgresql_user, I can modify the yugabyte user to be a superuser with the following commands…

				
					yugabyte=# SET session_replication_role TO replica;
SET

yugabyte=# ALTER USER yugabyte WITH SUPERUSER;
ALTER ROLE

yugabyte=# SELECT usename, usesuper FROM pg_user ORDER BY 1;
     usename     | usesuper
-----------------+----------
 postgres        | f
 postgres_user   | f
 postgresql_user | t
 yugabyte        | t
(4 rows)
				
			

Have Fun!