For example, you can create the superuser john
with the password apple
using CREATE ROLE, CREATE GROUP or CREATE USER statement as shown below:
CREATE ROLE john WITH LOGIN SUPERUSER PASSWORD 'apple';
Or:
CREATE GROUP john WITH LOGIN SUPERUSER PASSWORD 'apple';
Or:
CREATE USER john WITH LOGIN SUPERUSER PASSWORD 'apple';
*Memos:
You can omit WITH
which is optional.
You must use ''
for PASSWORD
instead of ""
otherwise there is error.
You must log in with any superusers(e.g., postgres
).
By default, CREATE USER
without LOGIN
can still have LOGIN
attribute implicitly.
By default, PostgreSQL needs a password so you should set PASSWORD
.
And, you can alter the existing user(role) john
to a superuser with ALTER ROLE or ALTER USER statement as shown below:
ALTER ROLE john WITH SUPERUSER;
Or:
ALTER USER john WITH SUPERUSER;
*Memos:
You can omit WITH
which is optional.
You must log in with any superusers(e.g., postgres
).
ALTER GROUP statement cannot alter an existing user(role) to a superuser.
In addition, if you want to drop the superuser john
, first, run these SQL below. *My answer explains how to drop a user(role) properly:
REASSIGN OWNED BY john TO postgres;
DROP OWNED BY john;
Finally, you can drop the superuser john
with DROP ROLE, DROP GROUP or DROP USER statement as shown below:
DROP ROLE john;
Or:
DROP GROUP john;
Or:
DROP USER john;