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
postgres@sanjeeva:/home/sanjeeva/postgres$

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 http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
root@sanjeeva:/etc/apt/sources.list.d#

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 http://apt.postgresql.org/pub/repos/apt/ 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 https://www.postgresql.org/media/keys/ACCC4CF8.asc
–2020-10-15 22:30:57–
https://www.postgresql.org/media/keys/ACCC4CF8.asc
Resolving www.postgresql.org (www.postgresql.org)… 87.238.57.232, 72.32.157.230, 217.196.149.50, …
Connecting to www.postgresql.org (www.postgresql.org)|87.238.57.232|: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#

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

Execute apt update before installation

root@sanjeeva:/home/sanjeeva# apt-get update
Hit:1 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists… Done
root@sanjeeva:/home/sanjeeva#

Once we update, we are ready to execute installation.


root@sanjeeva:/home/sanjeeva# apt-get install postgresql-11
Hit:1 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu 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) …
root@sanjeeva:/home/sanjeeva#

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