Question

postgres new user

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


Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
January 22, 2025

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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.