In this blog I will demonstrate how to install PostgreSQL database on Ubuntu.
Step #1:
List the Postgres related packages that already installed
dpkg -l | grep postgres
For example:
dpkg -l | grep postgres
ii postgresql-12 12.12-0ubuntu0.20.04.1 amd64 object-relational SQL database, version 12 server
ii postgresql-client-12 12.12-0ubuntu0.20.04.1 amd64 front-end programs for PostgreSQL 12
ii postgresql-client-common 214ubuntu0.1 all manager for multiple PostgreSQL client versions
ii postgresql-common 214ubuntu0.1 all PostgreSQL database-cluster manager
Step #2:
In case some packages are not needed run the "sudo apt-get --purge remove ..." command to purge them:
For example:
sudo apt-get --purge remove postgresql-12 postgresql-client-12
Step #3:
Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Step #4:
Import the repository signing key:
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
Step #5:
Update the package lists:
sudo apt update
Step #6:
Install the latest version of PostgreSQL:
sudo apt install postgresql postgresql-client -y
Step #7:
If you want a specific version, use 'postgresql-13' or similar instead of 'postgresql':
sudo apt install postgresql-13 postgresql-client-13 -y
Step #8:
Check status
sudo systemctl status postgresql
Step #9:
Check PostgreSQL client version
psql --version
For example:
dmi@dmi-VirtualBox:~$ psql --version
psql (PostgreSQL) 13.9 (Ubuntu 13.9-1.pgdg20.04+1)
dmi@dmi-VirtualBox:~$
Step #10:
Check PostgreSQL Server version
sudo -u postgres psql
postgres=# select version();
For example:
postgres=# select version();
version
-----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 13.9 (Ubuntu 13.9-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
(1 row)
Top comments (0)