PostgreSQL Installation on Ubuntu

There are multiple ways of installation of the PostgreSQL database on Unix like platforms.

We will explore the installation of PostgreSQL version 11 on Ubuntu 18.04 LTS using apt installation.

Let’s start.

Login to Ubuntu and check the version of Ubuntu.

postgres@sanjeeva:/home/sanjeeva/postgres$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic

PostgreSQL allows us to download many version across multiple platform, one should visit its official download page for downloading the required version.

By default, it will prompt to download latest stable version. Once version, platform and it’s architecture selected, it will provide the complete command for installation of the selected version.

However, before performing this installation task you should validate if repository is correctly created for the intended version i.e. 11 here. To create correct repository for version 11, We can manually create the entries. Go to folder /etc/apt/sources.list.d and create a file with extension .list with the content bionic-pgdg

root@sanjeeva:/etc/apt/sources.list.d# vi pgdg.list
root@sanjeeva:/etc/apt/sources.list.d# more pgdg.list
deb bionic-pgdg main

This would be different in different version of Ubuntu. The list here can be used

  • 20.04 - focal
  • 18.04 - bionic
  • 16.04 - xenial

Since, we are using version 18.04 here, So we are using bionic. This reposity can be created using any text editor like vi, nano etc. We will use echo here:
echo “deb bionic-pgdg main” > /etc/apt/sources.list.d/pgdg.list

Once repository is installed, we can start installation of PostgreSQL database. If we have to install a specific version we should supply the version number in apt command, else the installer will install it’s default version. To proceed with, we should install the key as well.

root@sanjeeva:/home/sanjeeva# wget
–2020-10-15 22:30:57–
Resolving (…,,, …
Connecting to (||:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 4812 (4.7K) [text/plain]
Saving to: ‘ACCC4CF8.asc’
ACCC4CF8.asc 100%[===================================================>] 4.70K –.-KB/s in 0s
2020-10-15 22:30:59 (685 MB/s) – ‘ACCC4CF8.asc’ saved [4812/4812]

root@sanjeeva:/home/sanjeeva# apt-key add ACCC4CF8.asc

Execute apt update before installation

root@sanjeeva:/home/sanjeeva# apt-get update
Hit:1 bionic-pgdg InRelease
Hit:2 bionic InRelease
Hit:3 bionic-security InRelease
Hit:4 bionic-updates InRelease
Hit:5 bionic-backports InRelease
Reading package lists… Done

Once we update, we are ready to execute installation.

root@sanjeeva:/home/sanjeeva# apt-get install postgresql-11
Hit:1 bionic-pgdg InRelease
Hit:2 bionic InRelease
Hit:3 bionic-security InRelease
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/11/main … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting default timezone … Asia/Calcutta
selecting dynamic shared memory implementation … posix
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok

Success. You can now start the database server using:

pg_ctlcluster 11 main start
Ver    Cluster      Port Status Owner Data directory Log file
11     main     5434 down postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log

update-alternatives: using /usr/share/postgresql/11/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode invoke-rc.d: could not determine current runlevel
Processing triggers for libc-bin (2.27-3ubuntu1.2) …
Processing triggers for systemd (237-3ubuntu10.42) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
Processing triggers for ureadahead (0.100.0-21) …

With this our installation is done. The PostgreSQL cluster installed is ready to start. We can start this using service postgresql start or by other means. We will explore this into next blog in details

Leave a Reply

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

Tum Laut Jao Priye