The latest version of this database system is PostgreSQL 13.2, while versions 12.6, 11.11, 10.16, 9.6.21, & 9.5.25 still getting regular updates. This tutorial describes how to install the latest PostgreSQL on Ubuntu 20.04 LTS Linux system. Also, include the steps to install pgAdmin4.

Prerequisites

A running Ubuntu 20.04 LTS system with shell access. Log in as a sudo user and press “CTRL+ALT+T” to open a terminal. Then install a few required packages.

Step 1 – Install PostgreSQL in Ubuntu 20.04

First of all, Import the repository signing GPG key to your system. Open a terminal and use the below command to import key: Next, create a PPA file for PostgreSQL on your Ubuntu 20.04 system. After adding the PPA to your system. Execute the following command to install the PostgreSQL server on your system.

Press ‘y’ for any confirmation prompted by the installer. The above command will install the latest version of the PostgreSQL server on your Ubuntu system. After successful installation verify the PostgreSQL service:

Step 2 – Connection To PostgreSQL

Now, establish a connection with the newly installed Postgres database server. First switch to the system’s Postgres user account: then type “psql” to get the postgress prompt:

Instead of switching users to connect to PostgreSQL, You can also combine both of the above commands as a single command. Once you are connected to PostgreSQL and you can see the connection information’s details, use the following command: The output displays information on the database name, the account you are logged in to, the socket path, and the port number.

Step 3 – Secure PostgreSQL

PostgreSQL installer creates a user “postgres” on your system. Default this user is not protected. First, create a password for the “postgres” user account by running the following command. Next, switch to the “postgres” account Then switch to the Postgres system account and create a secure and strong password for PostgreSQL administrative database user/role as follows. Restart the service to apply security changes.

Step 4 – Install pgAdmin

We can use the official pgAdmin4 PPA to install the latest version of pgAdmin on your system. First, import the repository signing GPG key and add the pgAdmin4 PPA to your system using the following commands. After adding the PPA, update the Apt cache and install the pgAdmin4 package on your system. The pgadmin4 package contains both pgadmin4-web and pgadmin4-desktop versions, Here:

pgadmin4-web – Provides the web interface accessible in a web browser pgadmin4-desktop – Provides desktop application for Ubuntu system, which required Ubuntu Desktop system.

You can install both or one of them of your choice. If you have installed both or pgadmin4-web, run the below command to configure it. This will add a login screen to the pgAdmin4 web dashboard. The above script will prompt you to create a user to access the web interface. Input an email address and password when prompted. Say “y” for other confirmation asked by the script. Once the script finished, you are good to access the pgAdmin web dashboard. It will be available at the below address: Access this in a web browser: http://localhost/pgadmin4

In any case, the above page is not loading, restart the Apache server using “sudo systemctl restart apache2“. Again try to load the above URL Now login with the email address and password configured with /usr/pgadmin4/bin/setup-web.sh script. After successful login to pgAdmin4, you will see the below screen.

Here you need to add your Postgres server to pgAdmin4. Click on the “Add New Server” button. This will open a popup, Enter a friendly name, database host, and Postgres login credentials. Click “Save” to complete the connection. On successful authentication, you will see the databases in the sidebar as shown below screenshot.

All done. You have successfully added the Postgres database server to pgAdmin4. You can also add more database instances to a single pgAdmin4 server.

Conclusion

In this tutorial, you have learned to install a PostgreSQL server on a Ubuntu 20.04 system. Additionally, you have learned to install and configure pgAdmin4 on your system. Next, you can learn about backup and restore Postgres databases via command line.

How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 56How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 71How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 5How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 1How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 80How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 4How to Install PostgreSQL and pgAdmin4 in Ubuntu 20 04   TecAdmin - 60