← Notes

March 8, 2021

Create a new user and database in PostgreSQL

Create a new user and database in PostgreSQL


First switch to the user that owns the database. By default the user is postgres.

su - postgres

To create a new user use:

createuser --interactive --pwprompt

Now let's create the database and assign the user we just created to be the owner.

createdb -O <user> <database-name>

Enter into the psql console:

psql

Give the proper permissions to the new user. To give access to the entire database use the following:

GRANT ALL PRIVILEGES ON DATABASE <database-name> TO <user>;