Creating user, database and adding access on PostgreSQL

Arnav Gupta
Mar 14, 2017 · 2 min read
A nice postgres installation graphic by http://digitalocean.com. DO hosts great servers, check them out.
sudo -u postgres psql
postgres=# create database mydb;
postgres=# create user myuser with encrypted password 'mypass';
postgres=# grant all privileges on database mydb to myuser;

$ sudo -u postgres psql

Creating user

$ sudo -u postgres createuser <username>

Creating Database

$ sudo -u postgres createdb <dbname>

Giving the user a password

$ sudo -u postgres psql
psql=# alter user <username> with encrypted password '<password>';

Granting privileges on database

psql=# grant all privileges on database <dbname> to <username> ;

Doing purely via psql

CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;

Coding Blocks

Daily Tidbits on Android, Javascript and Machine Learning

Arnav Gupta

Written by

Swimmer, Coder, Poet, Engineer, Entrepreneur. Co founder of Coding Blocks. Mobile Platform at Zomato

Coding Blocks

Daily Tidbits on Android, Javascript and Machine Learning