How to Install PostgreSQL on Ubuntu 22.04

Ubuntu

PostgreSQL is a free and open source relational database management system (ORDBMS) emphasizes scalability and SQL compliance. It is known for its strong reputation for reliability, data integrity, and performance.

PostgreSQL available for Linux, WindowsFreeBSD, OpenBSD and macOS.

In this post we will see how to install PostgreSQL above Ubuntu 22.04.

Install PostgreSQL on Ubuntu 22.04

You can install PostgreSQL database server from,

  1. Ubuntu Repository
  2. PostgreSQL Repository

1. Install PostgreSQL from Ubuntu Repository

Installing PostgreSQL from the Ubuntu repositories is a simple method. It takes almost 5 minutes to install PostgreSQL.

First, update the repository index.

sudo apt update

Then install the latest PostgreSQL (v14) version using the below command.

sudo apt install -y postgresql

Now the PostgreSQL service should be up and running. You can check the status of the service with the command below.

sudo systemctl status postgresql

Output:

 postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Wed 2022-05-25 01:39:45 EDT; 2min 5s ago
    Process: 4794 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 4794 (code=exited, status=0/SUCCESS)
        CPU: 1ms

May 25 01:39:45 ubuntu2204 systemd[1]: Starting PostgreSQL RDBMS...
May 25 01:39:45 ubuntu2204 systemd[1]: Finished PostgreSQL RDBMS.

2. Install PostgreSQL from PostreSQL Repository

The PostgreSQL Global Development Team publishes packages for the Ubuntu operating system through dedicated repositories, and the packages in their repositories are newer than those found in the OS repositories.

As of this writing, the PostgreSQL Global Development Team has not yet provided packages for Ubuntu 22.04. So use Ubuntu base repository to install PostgreSQL.

Change PostgreSQL server listening address

By default, PostgreSQL listens on localhost (127.0.0.1). This behavior restricts external applications from connecting to the database. Therefore, you need to configure PostgreSQL to listen to the system’s IP address to allow connections from external applications. To do that, edit postgresql.conf file.

sudo nano /etc/postgresql/14/main/postgresql.conf

Then put listen_addresses arrive * or system <IPAddress>.

listen_addresses = '192.168.0.10'

Finally, restart the PostgreSQL service.

sudo systemctl restart postgresql

Access PostgreSQL Database Server

To manage PostgreSQL databases, you will need to log in as postgres user (Linux user) and must invoke the PSQL shell using psql request.

sudo -u postgres psql

Output:

psql (14.3 (Ubuntu 14.3-0ubuntu0.22.04.1))
Type "help" for help.

postgres=#

Above psql shell, run the command below to change postgres user (Database Administrator Password).

postgres=# \password

OR

postgres=# \password postgres

Inference

That is all. I hope you learned how to install PostgreSQL above Ubuntu 22.04.

Hope this helps!

Source link

Share: