Code With Ben Knox

Creating a Postgres User

Databases

August 24th, 2025

A common task I have to handle when building an application or spinning up a resource is creating a database in postgres. Below are the steps I take when I need to create a dedicated database and user.


Prerequisites

I am assuming some basic knowledge of working with postgres, connecting to a database, creating a database server, etc.


Also below are some basic links to documentation:


You need to have a postgres database, here is the installation documentation.

You must have a client to connect to your database, I recommend dbeaver, download here.

You must also connect to the database server, here is a documentation for connecting with dbeaver


Assuming you are connected to the database, follow the steps below!


Create a Database

Optionally create a database or use the postgres database by default. You can do this with dbeaver if you'd like, but below is the sql command to do it:


Create a User

Now run the command to create a user, replace <your password> with your password:


Grant All Privileges

In my case I want this user to have all privileges granted on the database:


Of course you can customize these privileges, here is a link to the relevant documentation for user permissions.


Conclusion

That's all that is necessary for creating a user with privileges to perform any necessary operations in postgres!