create postgres database and user from command line

Summary: In this article I tried to explain how to create database, database user in postgresql through terminal commands.

These are some basic steps to follow for newbie how to use postgres database!
1:- Create database:

First install the postgresql on your server or locally.
Then follow the below steps to create the Database!
by default there is no database in postgres so you have to use the default user.

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

insert the command
#psql template1


2:Add user shahmeer
template1# CREATE USER shahmeer WITH PASSWORD 'helloE^$(0~E';

3: Create Database firstdb:
template1=# CREATE DATABASE firstdb;

Now grant all privileges on database

template1=# GRANT ALL PRIVIGES ON DATABASE firstdb to shahmeer;

Type \q to quit:

template1# \q 
Test user shahmeer login:
psql -U shahmeer -d firstdb
firstdb: \l;
will show all the databases in postgresql:

Hope this will help the new linux users.

Leave a Reply

Your email address will not be published. Required fields are marked *