cmd to Install PostgresQL on Ubuntu

Hi Guys, Welcome to Proto Coders Point. This article is on install postgresql ubuntu 20.04 | 22.04. Let’s get Started.

Introduction on PostgreSQL

PostgreSQL, In short also called as postgres, Is an advanced relational database management system using which you can implement SQL Query task.

In this article on how to quicky install postgreSQL on Ubuntu & run Postgres database server on ubuntu.

Install PostgreSQL on Ubuntu aws Se...
Install PostgreSQL on Ubuntu aws Server & Config postgres for remote connection using pgadmin
Requirement

To follow the steps along with this tutorial, you need a ubuntu server (aws/azure/google cloud) or a local ubuntu system any version 20.04 | 22.04

Video Tutorial

Video tutorial on installing postgresql on ubuntu server

Let’s Install it.

Just run below commands on ubuntu terminal, Thus it will install postgres.

Step 1: Updates the list of packages

To install PostgreSQL, firstly refresh ubuntu packages.

sudo apt update

Step 2: Add PostgreSQL 13 repository on Ubuntu

Install wget on ubuntu

sudo apt install wget ca-certificates

Download ca-certificates

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

Now, All the required files is been download using above wget command.

Again update packages using apt update.

sudo apt update

Step 3: Install PostgreSQL on ubuntu

sudo apt install postgresql postgresql-contrib
Install Postgresql on ubuntu 20.04

Step 4: Check postgresql status

sudo service postgresql status
check postgresql status

Step 5: Restart/Start postgresql

If postgres status is shown inActive, Then restart it by using below command.

sudo service postgresql restart

Step 6: Start using postgreSQL in Terminal

Enter postgre cli by changing user.

sudo -u postgres psql

How to check postgreSQL running port

by default, postgres will be running on port number 5432.

\conninfo

Check List of Roles & DB Access

\l   - Check List of user's
\du  - Check role(user) and Permission.