Atler owner of db
ALTER DATABASE name OWNER TO new_owner;
Create the user
postgres@hostname:~$ createuser
Enter name of role to add: username
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
postgres@hostname:~$
Create the DB
postgres@hostname:~$ createdb databasename
CREATE DATABASE
postgres@hostname:~$
Grand access for the user to the DB And last, using the psql command, set a password for the user and grant accesses :
postgres@hostname:~$ psql
postgres=# ALTER USER username WITH ENCRYPTED PASSWORD 'password';
ALTER ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE databasename TO username;
GRANT
postgres@hostname:~$