How to add psql database and assign user

Category: SQL :: Published at: 27.05.2022

Here you can find quick tips, how to create a database in postgresql + you will also get the knowledge
about assigning user to the created database.

1. At first we are turning on our postgresql console with the user we have created.
Remember that the name of your user depends on the configuration, and accounts you have created.
My user is called just postgres

>> psql -U postgres --password

The console will ask us about password. After typing the correct password it will sign us inside the console.

2. Now we need to create our databases. If our projects is made in rails, we should create 2 databases:

CREATE DATABASE applicationname_development;
CREATE DATABASE applicationname_test;

3. If we do everything correct, we should have our new created data stores on the list of all databases.

4. Now we need to assign privileges to our databases:

grant all privileges on database applicationname_development to postgres;
grant all privileges on database applicationname_test to postgres;

Now, the postgres user should have full access to those databases.

We can write the login and password of this user for example in our database.yml file.


- Click if you liked this article

Views: 63