Q. How do I create a user account called tom and grant permission for called pio?

A. You need to use following commands.
=> adduser/ adduser to add a user to /etc/passwd file

=> psql => It is a terminal-based front-end to .

=> CREATE USER – Adds a new user to a PostgreSQL database cluster.

=> CREATE DATABASE – create a new database

=> GRANT ALL PRIVILEGES – define access privileges

Procedure to add a user to PostgreSQL database

To create a normal user and an associated database you need to type the following commands. The easiest way to use is to create a Linux / UNUX IDENT authentication i.e. add user tom to UNIX or Linux system first.

Step # 1: Add a Linux/UNIX user called dbsql

Type the following commands to create a UNIX/Linux user called tom:
# adduser dbsql
# passwd dbsql

Step # 2: Becoming a superuser

You need to login as database super user under postgresql . Again the simplest way to connect as the postgres user is to change to the postgres unix user on the database using su command as follows:
# su - postgres

Step #3: Now connect to database server

Type the following command
$ psql template1
$ psql -d template1 -U postgres

psql (9.2.18)
Type "help" for help.

Step #4: Add a user called tom

Type the following command to create a user called tom with a called myPassword (you need to type command highlighted with red color):
template1=# CREATE USER dbsql WITH PASSWORD 'myPassword';

Step #5: Add a database called pio

Type the following command (you need to type command highlighted with red color):
template1=# CREATE DATABASE pio;
Now grant all privileges on database
template1=# GRANT ALL PRIVILEGES ON DATABASE pio to dbsql;
Type \q to quit:
template1=# \q

Step #6: Test dbsql user login

In order to login as tom you need to type following commands. Login as tom or use su command:
$ su - dbsql
$ psql -d pio -U dbsql


psql (9.2.18)
Type "help" for help.
Print Friendly, PDF & Email



Bài viết liên quan