Add user account to PostgreSQL database

Add user account to postgreSQL database


Step:1 Add user to unix/linux - debian system

First you have issue following command to add unix/linux user..

# adduser user

It will ask name, password and bla bla.........

You can change password by issuing command like this...

# passwd password

Step:2 Becomming a super user...

# su - postgres

Then u can connect to the database..

# psql template1

or

# psql -d template1 -U postgres

Step:3 Add user....

It creates user called "user" and password called "password"

template1=# CREATE USER user WITH PASSWORD 'password';

Step:4 Add a database called testdb....

template1=# CREATE DATABASE testdb;

Add user account to postgreSQL database

Step:5 Grant privileges to that database...

template1=# GRANT ALL PRIVILEGES ON DATABASE testdb to user;

exit from psql..

template1=# \q

Step:6 Try to connect database ....

Try to connect to the database "testdb" user "user"

# su - user
# psql -d testdb -U user

enjoy......

Comments