Saturday, May 28, 2016

create new user for postgreSQL

by default we can access postgresql using user postgres without password on local machine. and we use that user to create new user and grant permission one database for that new user.

for basic postgresql operation follow link below
http://www.atechnote.com/2016/03/basic-postgresql-operation.html


1- create local new user call newpsqluser and set password for it
$ sudo useradd newpsqluser -m
$ sudo password newpsqluser

2- access postgresql shell and create a new user call newpsqluser and grant a permission on database tryton
$ sudo su root
# sudo -u postgres psql
 
 postgres=# CREATE USER newpsqluser WITH PASSWORD 'assword';
CREATE ROLE
postgres=# CREATE DATABASE tryton;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE tryton to newpsqluser;
GRANT

postgres=# create database newpsqluser;
CREATE DATABASE
postgres=# \q



3- now you can access to postgres using user newpsqluser. There are two ways to access:

- access postgresql shell without password
$ sudo su root
# sudo -u postgres newpsqluser
psql (9.5.2)
Type "help" for help.
newpsqluser=>


- access postgresql shell with username and password
$ psql -h localhost -U newpsqluser
Password for user newpsqluser:
psql (9.5.2)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
newpsqluser=>

No comments:

Post a Comment