Install PostgreSQL On Ubuntu Linux

Install PostgreSQL On Ubuntu Linux

PostgreSQL, or Postgres, is a free, powerful, and open-source relational database management system developed at the University of California.

In this tutorial post, We are going to show you the steps to install PostgreSQL on Ubuntu Linux along with the pgAdmin4 web-based management tool.

How To Install PostgreSQL On Ubuntu Linux

PostgreSQL packages are included in Ubuntu default repositories but it might not be the latest version. Our answer to your question of how to install PostgreSQL and pgAdmin4 Ubuntu Linux is below:

Run the commands below to add the PostgreSQL repository key and file to Ubuntu operating system:

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'

Now, run the commands below to update and install the latest PostgresSQL packages in your Ubuntu Linux:

To install PostgreSQL 11, run the commands below

sudo apt update
sudo apt-get install postgresql postgresql-contrib

After you are done with the process of installing PostgreSQL in Ubuntu, run the following commands below to stop, start and enable.

sudo systemctl stop postgresql.service
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service

Now if you want to validate that PostgreSQL is installed and running, run the commands below.

sudo systemctl status postgresql.service

You might see something like below:

READ More Relevant Stuff:  Configure CTRL+ALT+DEL As Task Manager In Ubuntu 20.04/18.04

When you run the commands above, it should show something similar to the one below.

● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
   Active: active (exited) since Wed 2021-10-10 10:21:01 CDT; 17s ago
 Main PID: 7930 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4663)
   CGroup: /system.slice/postgresql.service

Oct 10 10:21:01 ubuntu2004 systemd[1]: Starting PostgreSQL RDBMS.
Oct 10 10:21:01 ubuntu2004 systemd[1]: Started PostgreSQL RDBM

Now, if you want to use and access the PostgreSQL shell, you need to switch users and login to the shell as a Postgres user.

sudo su - postgres

Now use the psql command to invoke the interactive shell so that you can create and manage PostgreSQL databases.

psql

How to install pgAdmin4 web portal

Run the commands below to install pgAdmin4 in Ubuntu so that you can manage PostgreSQL server.

sudo apt-get install pgadmin4 pgadmin4-apache2

During the installation, you will be prompted to enter a PostgreSQL user password.

After installing, you can access the web portal by opening your web browser and going through the server hostname or IP address followed by pgAdmin4 URI

http://example.com/pgadmin4

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

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