Use the ALTER USER command with the SUPERUSER attribute to modify a user to a superuser in Postgres. The CREATE USER statement is the same as CREATE ROLE, with the exception that the CREATE USER statement has LOGIN privileges by default, whereas CREATE ROLE doesn’t. To create a superuser in Postgres, use the CREATE ROLE or CREATE USER statement with the SUPERUSER attribute. The output snippet proves that the hr_manager has been changed to a superuser successfully. Run the below command to check if the specified user has been changed to the superuser or not: \du The “ALTER ROLE” message in the output signifies that the given user has been altered to a superuser. Run the below-provided command to change the “hr_manager” from user to superuser: ALTER USER hr_manager WITH SUPERUSER Suppose we want to change a user named “hr_manager” to a superuser. Run the “\du” command to get the list of users: \du WITH is an option used to specify the SUPERUSER attribute.Įxample: How Do I Change/Modify a Simple User to Superuser in Postgres?įollow the steps provided below to change a particular user to a superuser in Postgres: User_name represents a user to be altered. Use the ALTER USER command with the SUPERUSER attribute to modify a user to superuser in Postgres: ALTER USER user_name WITH SUPERUSER How to Change/Alter a Simple User to Superuser in Postgres? Let’s verify the user creation via the below command: \du Ī superuser named “user_admin” has been created successfully. So you must specify the LOGIN attribute alongside the SUPERUSER attribute to create a superuser using CREATE ROLE statement: CREATE ROLE user_admin SUPERUSER LOGIN PASSWORD '12345' Run the “\du” command to verify the user creation: \du įrom the above snippet, you can authenticate that a superuser named “example_user” has been created successfully.Įxample 2: How Do I Create a Superuser in Postgres Using CREATE ROLE Statement?Īs mentioned earlier, the CREATE ROLE statement has no login credentials/privileges by default. The “CREATE ROLE” message in the output indicates that the user has been created. Let’s execute the below statement from the SQL Shell to create a superuser in Postgres: CREATE USER example_user SUPERUSER To create a superuser, you can also use the CREATE ROLE statement as follows: CREATE ROLE user_name SUPERUSER LOGIN PASSWORD 'password' Įxample 1: How Do I Create a Superuser in Postgres Using CREATE USER Statement? To create a superuser in Postgres, use the CREATE USER statement followed by the user name and finally specify the SUPERUSER attribute: CREATE USER user_name SUPERUSER In Postgres, the CREATE ROLE or CREATE USER statements are used to create a user/role. This Postgres blog will teach you how to create a superuser or change a user to a superuser via practical examples. Managing a system requires a superuser account, which has broad privileges. In PostgreSQL, a superuser bypasses all the permission checks except for logging in.
0 Comments
Leave a Reply. |