Install PostgreSQL with pgAdmin on Ubuntu 20.04 | 18.04

This brief tutorial shows students and new users how to install PostgreSQL on Ubuntu 20.04 | 18.04 with pgAdmin4 web tool.

PostgreSQL is a general purpose and object-relational database management system, probably the most advanced open source database system…. you can also add custom functions using different programming languages such as C/C++, Java, etc.

pgAdmin is a web-based interface for managing of PostgreSQL database instances easily from your web browser…  This brief tutorial shows students and new users how to install PostgreSQL server on Ubuntu and manage it via pgAdmin4.

If you’re not a seasoned database administrator and you want to manage PostgreSQL easily via your favorite web browser, then use pgAdmin4.

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

Step 1: Add PostgreSQL Repository

Adding PostgresSQL repository to Ubuntu is easy… all you have to run is run the commands below to add the repository key.,., the key is there to authenticate and validate packages from the repository….

Run the commands below to add the repository key and the repository.

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

When you’re done… continue below…

Step 2: Update and Install PostgreSQL

Now that the repository and key are added, run the commands below to update and install the latest PostgresSQL packages..

To install PostgreSQL 11, run the commands below

sudo apt update
sudo apt-get install postgresql-11

After installing PostgreSQL, the commands below can be used to stop, start, enable and check its status

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

This is what the status command shows

● 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.

Step 3: Creat PostgreSQL Linux User Password

After installing PostgreSQL, it’s a good idea to create / change the default PostgreSQL user password… Run the commands below to create / change the user password in the bash shell and not PostgreSQL interactive shell.

Set password for Linux user (postgres)

sudo passwd postgres

You should be prompted to create a new Linux password for postgres user.

Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

After setting a new password, every time you want to access PostgreSQL interactive shell, you’ll be prompted to confirm the password you created after running the commands above…

Step 4: Accessing PostgreSQL

Now that PostgreSQL is installed, to access its interactive shell and manage databases… you need to log in as the postgres user… to do that run the commands below:

sudo su -l postgres

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


Set password for DB administrator (postgres)

su - postgres

On psql shell, run below command to change database admin password.

postgres=# \password
postgres=# \password postgres

After that, quit and exit..


Step 5: Installing pgAdmin4 Web Interface

Now that PostgreSQL is installed, run the commands below to install pgAdmin4 to use to manage your PostgreSQL server…

sudo apt-get install pgadmin4 pgadmin4-apache2

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

PostgreSQL pgAdmin4

Create a password for pgAdmin4 web service.

PostgreSQL pgAdmin4

After installing, open your web browser and browse to the server hostname or IP address followed by pgAdmin4 URI

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

PostgreSQL pgadmin4

Login and add a new PostgreSQL server.


PostgreSQL pgadmin4

That’s it! You may want to restrict access to only local IP address.


This post showed you how to install PostgreSQL on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report.

You may also like the post below:


  1. Thank you thank you!

  2. Thank you so much! Por fin lo hice!

  3. after installation, what should I do in the browser to enter the pgadmin page?

  4. after hit that example url i am getting 404 – Not Found error

  5. Im having this errors

    unpacking pgadmin4-apache2 (4.25-1.pgdg20.04+1) …
    dpkg: error processing archive /var/cache/apt/archives/pgadmin4-apache2_4.25-1.pgdg20.04+1_all.deb (–unpack):
    trying to overwrite ‘/etc/apache2/conf-available/pgadmin4.conf’, which is also in package pgadmin4-web 4.28
    Errors were encountered while processing:
    E: Sub-process /usr/bin/dpkg returned an error code (1)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.