For accessing the PostgreSQL database you can use the command line or GUI. If you want to access and use PostgreSQL in GUI mode then you will have to install pgAdmin 4. It will provide you a web interface and also an app interface. The GUI mode is a little different from the phpMyAdmin. But, it is pretty and easy to use. You will be able to use and manage the PostgreSQL database easily from its GUI mode. The pgAdmin is the leading Open Source management tool for Postgres. It is the world’s most advanced Open Source database. The pgAdmin graphical interface simplifies the creation, maintenance, and use of database objects. Today, in this post, I will gonna show you the complete steps to install pgAdmin 4 on the Ubuntu platform. In my previous post, I have already shown you the installation of Postgres in Ubuntu.
If you haven’t installed the Postgres then it is highly recommened to go through the above post first. Actually, pgAdmin 4 will require to have the Postgres. So, let’s continue to the post.
Prerequisites
- Ubuntu 20.04.2 LTS (As an Operating System)
- An Ubuntu user with Sudo Privileges
- A terminal and command-line access
- PostgreSQL (>=10)
Install pgAdmin 4 in Ubuntu
Before installing the pgAdmin 4, you can check the PostgreSQL apt package in Ubuntu.
sudo apt show postgresql
The above command will return the installed package with lots of other descriptions.
Now, we can proceed the installation.
Setup Repository to Install pgAdmin 4
In the first step of the installation, you will have to add the repository for pgAdmin. This will iniate the installation by adding the package.
sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
The above command will add the repository. But also, it will add a public key for the repository. You can see the last statement in above command.
After adding the public key, it will return the below response.
After adding the repository and public key, it will require to create a configuration file.
How to Configure Apache Virtual Host in Ubuntu 20.04
Create Configuration File For pgAdmin Repository
In this step, we will create a configuration file for the added repository file.
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
It will take a couple of seconds to complete it.
After completing the above step, let’s install pgAdmin.
How to Install MySQL Workbench in Ubuntu 20.04 LTS
Install pgAdmin 4 in Ubuntu
In this step, just add the below command and hit enter.
sudo apt install pgadmin4
It will start insalling the pgAdmin 4 based on the added repository and configuration.
It will prompt you for the permission, so just allow it to complete the installation.
Once, it is finished, you are done. Now, you can search the pgAdmin installed in your system.
How to Install and Setup VS Code in Ubuntu 20.04 LTS
Connect and Use pgAdmin 4 in Ubuntu
After the installation, just find out pgAdmin through the name. Now, open it.
In the next step, it will ask you to create a master password for the login access. Remember, this is not the root password for the PostgreSQL. It is just for the GUI (pgAdmin).
After setting the password, you will be entered inside the dashboard. From here, you can create and manage the database.
Create MySQL User And Grant Privileges in Ubuntu 20.04
Create Server in pgAdmin 4
For creating and using the database, firstly, you will have to create a server. So, simply click on the Add New Server in the dashboard. Or either you can click on the Servers->Create Server option. It will open a dialog window as showing below.
Now, switch to the connection tab and specify the host name. Here, we are connecting the localhost so, just enter the hostname as localhost.
If you want to connect to the online server then you can put the public IP address of your server. Leave the port to default. If you haven’t changed the default username and password then leave it to default. If you have already set any password for the default user then you can enter the password here.
Now, click on the save button. It will save the configuration setting for creating a new server. Once it is saved, you can see the server is created, and you will be able to see and acess the created databases.
So, this was the app mode of the pgAdmin. Here, we have accessed through the desktop mode. But, we can access the pgAdmin 4 in web mode.
How to Install Composer For PHP in Ubuntu 20.04 LTS
Configure pgAdmin 4 as Web Mode
This is the awesome feature of pgAdmin that you can access it in two modes. We already seen the app mode in the above step. But, we can use it in web mode through the browser. For that, you have to enter the below command in the terminal.
$ sudo /usr/pgadmin4/bin/setup-web.sh
This command will enable the web mode and it will ask for the email and password. This email and password will be the login credentials for pgAdmin web mode. After that, you will have to allow permission to finish the process.
After completing the process, it will restart the apache server by default. Also, you can see the web mode URL on which you can access the pgAdmin in the browser.
You can open this URL in the browser or you can simply type the http://localhost/pgadmin4
.
In the above screen, you can see it is asking for the email and password that we created during the configuration. So, just enter it and hit the login button. After the login, you will be redirected to the dashboard of pgAdmin web mode.
Now, you can create a server as we created for the app mode. Then you can proceed creating the database and tables. That’s it for this post.
How to Install LAMP Stack in Ubuntu 20.04 LTS
Conclusion
We have installed the pgAdmin 4 in Ubuntu. It provides two mode for accessing the GUI for the database management. The app mode and the web mode. Both are the same. You can create a server and connect it for creating the database. You can connect it through the online server if you have. In that case, it will require the public IP address of the server. I hope you will not face any issue during the installation of pgAdmin. But in case, if you face then just put your comments below. I will help you as soon as possible.
Leave a Reply