How can i create new Superuser in postgres in par with postgres default user? I want this new user to have its own psw that i can use to access the database created
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
To create a new superuser, use the CREATE USER
command along with SUPERUSER
and LOGIN
options, and set the password for the new user. Replace new_username
with the desired username and your_password
with the password you want for this new user:
CREATE USER new_username WITH SUPERUSER LOGIN PASSWORD 'your_password';
Grant privileges to the new user:
This step isn’t always necessary because the SUPERUSER
role already provides full privileges, but you can explicitly grant all privileges to the new user on a specific database if needed:
GRANT ALL PRIVILEGES ON DATABASE your_database TO new_username;
Exit PostgreSQL:
Once the user has been created, exit the PostgreSQL prompt. Now you can try logging in with the new superuser account by running the following command:
psql -U new_username -d your_database -W
You’ll be prompted to enter the password for new_username
to access the database.
This will create a new superuser with the specified password, allowing you to access the database using this new user.
Heya, @charmeem
You can create the superuser using CREATE ROLE
CREATE ROLE new_username WITH SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD 'your_password';
You can manage privileges efficiently by creating a group role:
CREATE ROLE admin_group WITH SUPERUSER CREATEDB CREATEROLE NOLOGIN;
GRANT admin_group TO new_username;
This setup makes it easier to manage superuser-like privileges for multiple users.
Also assign superuser privileges only if absolutely necessary. For less sensitive tasks, consider roles with specific privileges instead.
Hope that this helps!
Hi there,
In addition to what has already been mentioned, if you are using a managed Postgres cluster, you can follow the steps on how to do that here:
https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.