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

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';
postgres=# CREATE DATABASE tryton;
postgres=# GRANT ALL PRIVILEGES ON DATABASE tryton to newpsqluser;

postgres=# create database newpsqluser;
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.

- 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.

No comments:

Post a Comment