How to install PostgreSQL 12 and pgAdmin 4 on Ubuntu 20.04

How to install PostgreSQL 12 and pgAdmin 4 on Ubuntu 20.04

PostgreSQL or Postgres is a Relational Database Management System (RDBMS) software with free & open source license. Starting as a POSTGRES project at the University of California, Berkeley in 1986, then in 1996 the name was changed to PostgreSQL which signifies supporting SQL. PostgreSQL runs on all major operating systems, Linux, FreeBSD, OpenBSD, macOS, and Windows.

1. Install PostgreSQL

Install PostgreSQL from the default Ubuntu repositories.

Default data directory is /var/lib/postgresql/12/main, configuration files are stored in /etc/postgresql/12/main , and the postgresql service runs on the port 5432.

Check if PostgreSQL service is active, running, and enabled.

Also check whether PostgreSQL is ready to accept connections from clients.

The result of the above command.

2. Access PostgreSQL

The PostgreSQL installation process create an account with the name postgres which becomes the PostgreSQL superuser. For PostgreSQL shell use psql.

Switch to postgres and login to psql.

The result of the above command.

3. Create Database

Create database, user, and grant database access rights to user.

4. Create New User

Login to psql with user postgres and create a new user.

The result of the above command.

When running psql, the PostgreSQL authentication system by default will use the active system user as the login user to psql, and that user must have a database with the same name as the user name.

For example, the username I use is musaamin, meaning there must also be a database with the name musaamin.

Creating a database with the name musaamin.

Login test with user musaamin.

The result of the above command.

Login to psql with another database connected.

Check the current connection to display the database name and user.

The result of the above command.

5. Install pgAdmin4

pgAdmin 4 is a management tool for the PostgreSQL database. pgAdmin supports Windows, Linux, and macOS operating systems. pgAdmin 4 was rewritten using Python and Javascript (jQuery).

pgAdmin 4 is not available in the default repositories, add the pgAdmin 4 repository.

Install pgAdmin 4.

The command above will install pgAdmin 4 and Apache web server to run pgadmin4-web. pgAdmin4 is stored at /usr/pgadmin4.

Create a user login for pgAdmin.

The result of the above command. Enter the email address and password to log into pgAdmin, and configure Apache for pgadmin-web.

The pgAdmin login page.

pgAdmin 4 login
pgAdmin 4 login

The pgAdmin dashboard page.

pgAdmin dashboard
pgAdmin dashboard

Click Add New Server.

General tab, enter Name for server name, for example localhost.

Tab Connection, enter Hostname/address for the PostgreSQL server hostname or IP address, for example localhost. Enter Username and Password .

Then Save.

pgAdmin - create connection
pgAdmin – create connection

pgAdmin is already connected to the PostgreSQL server on localhost.

pgAdmin connected
pgAdmin connected

Leave a Reply

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