DEV Community

Nick F
Nick F

Posted on

Postgesql - create a user for a database

How to setup a new user and give that user permission over a database? I found this a hard question to answer, so I'm writing down my soltuion.

This worked for me on Postresql 15.

You need a superuser account, to create the database.

create database <database name>;
create user <user name> with encrypted password '<password>';
alter database <database name> owner to <user name>;
Enter fullscreen mode Exit fullscreen mode

At that point, the user you created can login and create/edit/delete tables as you would expect within that one database.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay