Here I mentioning the steps require to Create a Postgres User and give them access to particular Database
Firstly run command “sudo su” to make a user as a super user
create a new User in unix or you can use the existing one as well,
You can create a new user by command
# adduser bob
# passwd bob
once the unix user get create you can open the Postgres by command
su postgres
then you can open postgres command prompt by typing “psql” in command prompt.
after that on PSQL Prompt you can create a User by following command
CREATE USER bob WITH PASSWORD ‘yourPassword’;
and if user already exist and if you not know his password then you can alter the password by command
ALTER USER bob WITH PASSWORD ‘yournewpassword’;
Once user get created and you know the password as well you can then create a database by using command
CREATE DATABASE db;
after database get created you can grant all the privilages of database to above created user
GRANT ALL PRIVILEGES ON DATABASE db to bob;
and then by \q you can get exit from the PSQL command prompt and not you can login to new PSQL created user using command
psql -U bob -d db;
and now have access to database db and login to psql as a User bob 🙂