How to install postgreSQL and pgAdmin4 on Ubuntu 18.04 LTS
PostgreSQL is a relational database management system, which is used widely and very much loved by the professionals. It is one of the most advanced database management system.

In this guide I will provide you instructions for the installation of postgreSQL and pgAdmin4 on Ubuntu 18.04 LTS operating system.

Installing postgreSQL

We can use apt install command to install the package as Ubuntu have Postgres packages in its repositories.

$ sudo apt update

$ sudo apt install postgresql postgresql-contrib

Now, you have system with PostgreSQL installed on it.

Using PostgreSQL

After getting installed, PostgreSQL creates a default user named “postgres”. Functionality of users are similar to that of other database management system like MySQL. We can start using PostgreSQL by typing following command on terminal.

$ sudo -i -u postgres

You will see something like this :

postgres@hostpcname:~$

You can then enter the PostgreSQL terminal by typing :

psql

Now you can access the databases.

To exit the PostgreSQL type:

\q

postgres@hostpcname:~$ exit

Installing pgAdmin4 inside a python environment :

pgAdmin4 is a free software project released under the PostgreSQL/Artistic licence. This software package helps in managing the databases.

Installation

As you are going to install pgAdmin4 on the a python environment, make sure that you have python installed on your system.

Checking python version :

$ python3 --version

Python 3.6.8

If you get this then you have python 3 installed. Now install virtualenv by using pip (pip3 for python 3).

pip3 install virtualenv

Working in a virtual environment make tasks isolated and easier to handle. Now create a virtual environment by using following command:

$ mkdir pgadmin4

$ cd pgadmin4

$ virtualenv pgadmin4

To activate the virtual environment type :

$ source pgadmin4/bin/activate

Now, we can install pgAdmin4 in this virtual environment.

Download the whl file:

Now install the package by typing :

$ pip install pgadmin4–4.8-py2.py3-none-any.whl

Afterwards, we need to configure and run pgAdmin4.

Create a new file called config_local.py in pgAdmin4/lib/python3.6/site-packages/pgadmin4/ by using following command:

$ gedit pgadmin4/lib/python3.6/site-packages/pgadmin4/config_local.py

Add the following text inside the file.

import os

DATA_DIR = os.path.realpath(os.path.expanduser(u"~/.pgadmin/"))

LOG_FILE = os.path.join(DATA_DIR, "pgadmin4.log")

SQLITE_PATH = os.path.join(DATA_DIR, "pgadmin4.db")

SESSION_DB_PATH = os.path.join(DATA_DIR, "sessions")

STORAGE_DIR = os.path.join(DATA_DIR, "storage")

SERVER_MODE = False

You are done with the installation and configuration.

let’s check if it works, you can run the pgadmin through following command.

$ python pgadmin4/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py

You will see something like this :

Starting pgAdmin 4. Please navigate to http://127.0.0.1:5050 in your browser.

As it is already telling, copy this url onto your browser and access pgadmin. You will see similar interface on your browser as shown in the screenshot.

To test that it is connected with the postgresql create a server. First tap on add new server and Configure the things as shown in the screenshots.
['Akash Srivastava']
['Postgresql', 'Postgres', 'Installation', 'Ubuntu', 'Python']