This post shows students and new users the steps to install PostgreSQL on Ubuntu Linux with the web-based administration tool pgAdmin4. PostgreSQL is a general purpose, object relational database management system, probably the most advanced open source database system.

With PostgreSQL, custom functions can also be added using different programming languages ​​like C / C ++, Java, etc.

pgAdmin is a web-based interface for managing PostgreSQL database instances easily from your web browser. If you are not an experienced database administrator and want to manage PostgreSQL easily through your favorite web browser, use pgAdmin4.

PostgreSQL packages are included in the default Ubuntu repositories, however the Ubuntu repositories versions are not the latest. To install the latest version, you will need to install the PostgreSQL package repository on Ubuntu Linux, and this tutorial will show you how.

Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern open source Linux operating system for desktops, servers, and other devices.

To learn how to install PostgreSQL and pgAdmin4 Ubuntu Linux, follow the steps below

How to add a PostgreSQL repository on Ubuntu Linux

Adding the PostgreSQL repository to Ubuntu is relatively easy. Just run the following commands to add the PostgreSQL repository file and key.

The following commands will add the repository key and repository file to Ubuntu Linux.

wget --quiet -O - | sudo apt-key add -
sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

How to install PostgreSQL on Ubuntu Linux

Now that the repository and key have been added, run the following commands to update and install the latest PostgresSQL packages.

YOU CAN ALSO READ:   How to add a user to the Sudoers file in Ubuntu Linux

To install PostgreSQL 11, run the following commands

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

The above commands will also install the PostgreSQL contrib package, which provides several additional features for the PostgreSQL database system.

After installing PostgreSQL, the following commands can be used to stop, start, and enable.

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

To validate that PostgreSQL is installed and running, run the following commands.

sudo systemctl status postgresql.service

When you run the above commands, it should display something similar to the following.

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

Oct 31 11:58:09 ubuntu1804 systemd[1]: Starting PostgreSQL RDBMS.
Oct 31 11:58:09 ubuntu1804 systemd[1]: Started PostgreSQL RDBMS.

How to access the PostgreSQL shell

When you install PostgreSQL, a postgres the user is created automatically. This user is the superuser of the PostgreSQL instance and is equivalent to the MySQL root user.

To access the PostgreSQL interactive shell and administer the database, you need to switch users and log in to the shell as a postgres user.

sudo su - postgres

Then use the psql command to invoke the interactive shell when you want to create and manage PostgreSQL databases.


Set password for the database administrator (postgres)

Another way to access the PostgreSQL prompt without changing user is to use the sudo command.

To create a PostgreSQL database administrator password change, log in as postgres user and invoke the psql command shell using the following commands.

sudo -u postgres psql

In the psql shell, run the following commands to change the database administrator password. Any of the following commands should work.

password postgres

After that, get out there and get out.


How to install the pgAdmin4 web portal

Now that PostgreSQL is installed, run the following commands to install pgAdmin4 and use it to manage your PostgreSQL server.

sudo apt-get install pgadmin4 pgadmin4-apache2

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

YOU CAN ALSO READ:   How to install Jenkins on Ubuntu Linux
PostgreSQL pgAdmin4

Create a password for pgAdmin4 web service.

PostgreSQL pgAdmin4

After installation, open your web browser and look for the server’s hostname or IP address followed by pgAdmin4 URI

Enter the initial user account of the web interface as shown in the image above.

PostgreSQL pgadmin4

Login and add a new PostgreSQL server.

postgresql configuration ubuntu pgadmin4 3

Start setting up your environment.

PostgreSQL pgadmin4

That is all! You may want to restrict access to the local IP address only.


In this tutorial we have seen how to install PostgreSQL on Ubuntu Linux and its web-based tool for managing databases. If you find any errors above or have something to add, use the comment form below.

Write A Comment