Skip to content

Instantly share code, notes, and snippets.

@vishnun
Created May 16, 2017 02:15
Show Gist options
  • Save vishnun/29cc75754d9cb35a11f0bdf8fbd7dceb to your computer and use it in GitHub Desktop.
Save vishnun/29cc75754d9cb35a11f0bdf8fbd7dceb to your computer and use it in GitHub Desktop.
Postgresql installation for ubuntu

Step 1: Add PostgreSQL Apt Repository

PostgreSQL packages are also available in default Ubuntu repository, But when I try to install PostgreSQL on Ubuntu 12.04 I only found PostgreSQL 9.1 was in default apt repository. So I request you to add PostgreSQL apt repository first in your system suggested on official PostgreSQL website using following command.

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

Step 2: Install PostgreSQL

Now as we have added PostgreSQL official repository in our system, First we need to update repository list. After that install Latest PostgreSQL Server in our Ubuntu system using following commands.

$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

Step 3: Connect to PostgreSQL

After installing PostgreSQL database server, by default it creates a user ‘postgres’ with role ‘postgres’. It also creates a system account with same name ‘postgres’. So to connect to postgres server, login to your system as user postgres and connect database.

$ sudo su - postgres
$ psql

Create Role

postgres=# create role rolename with LOGIN CREATEDB CREATEROLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment