In this guide, you will learn how to install PostgreSQL 11 and PgAdmin4 on Ubuntu 18.04 LTS.
Table of Contents
PostgreSQL
PostgreSQL is a free and open source cross-platform Relational Database Management System (RDBMS). It is widely used by developers in the development environment and in production environments as well. PostgreSQL 11 was released in November 2018 and comes with a wealth of new and exciting features.
PgAdmin
PgAdmin 4 is a free and open source web-based administration and development platform that helps users to administer, manage and monitor Postgres databases in a graphical manner. Let’s now dive in and see how we can install the two.
Install PostgreSQL on Ubuntu
Step 1: Importing GPG key & adding PostgreSQL APT repository
To get started, begin by importing the GPG key for the PostgreSQL packages. Use the command below to download the CA certificates.
$ sudo apt install wget ca-certificates
Sample Output
Next, run the command below to import the GPG key to your system.
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Output
Step 2: Adding PostgreSQL apt repository to System
Once done with importing the GPG key, append the PostgreSQL apt repository on your system.
$ sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
Step 3: Installing PostgreSQL 11 on Ubuntu
Before installing PostgreSQL 11, first, update the system repositories as shown.
$ sudo apt-get update
Next, run this command to install PostgreSQL 11.
$ sudo apt-get install postgresql postgresql-contrib
Output
Step 4: Connecting to PostgreSQL 11
By default, PostgreSQL database server creates a user ‘postgres‘ having the role ‘postgres‘.
To connect to the PostgreSQL 11 server, log in to your system and run the command below to change to the postgres user.
$ sudo su - postgres
NOTE: The ‘postgres’ user’s password is disabled by default.
Finally , to connect to the PostgreSQL 11 database server use the psql
command as shown.
psql
Output
To check login information, run the command below.
postgres-# \conninfo
Output
Installation of PgAdmin4
To begin the installation of PgAdmin4, run the command below.
$ sudo apt-get install pgadmin4 pgadmin4-apache2
Output
During the installation process, you will be prompted for an email address as shown below. This is the email address you will use to log in to the PgAdmin4 interface.
Provide an email address of your choice
Next, you will be prompted for your password. Provide your preferred password. The system will then proceed to wrap up the installation of PgAdmin4.
Great ! At this point you have successfully installed PgAdmin4.
Connecting to PgAdmin4
Now that we have successfully installed PgAdmin4, it’s time now to connect to it. Open your browser and browse your server’s IP address as shown
https://IP-address/pgAdmin4
In our example, the URL is:
https://38.76.11.34/pgAdmin4
You will see the following login page. Enter the email address and password that you provided during the setup of PgAdmin4 and hit ‘Login’.
You will finally be presented with the PgAdmin4 dashboard as shown below.
With the dashboard, you can now create database server instances as well as monitor the performance of your databases.
This wraps up the topic of how to install PostgreSQL 11 and PgAdmin4 on Ubuntu server. Feel free to reach out to us with your feedback and share the article on your social platforms.
After installation, /pgadmin4 login says
Bad Request
The CSRF tokens do not match.
Any solution?
I am new for coding, I followed all the steps finally i gave my IP address, but its giving an error saying ” site cant be reached”. please help me with this
Hi , it doest not work for me, it says that apache2 is not active , my be because i have nginx installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package pgadmin4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘pgadmin4’ has no installation candidate
E: Unable to locate package pgadmin4-apache2
Hi: Quick question. Do I need to have PostgreSQL server installed on my workstation, in order to install pgAdmin4? The reason I ask is that I only want to use it to connect to remote databases. I have no intention of running a database server on my workstation. Please advise. Thanks very much for these instructions.
Regards,
Brent.
No, I don’t think so. You can install pgAdmin4 without installing PostgreSQL.
Many thanks for this article. It’s the best article for me. Good luck! 🙂
Hi, I think there’s a typo on Step 3. Instead of sudo apt-update is sudo apt-get update
Thanks for noticing it, I have fixed it.
What’s the diff b/w apt and apt-get ??