How to Install PostgreSQL on Red Hat Enterprise Linux 9

How to Install PostgreSQL on Red Hat Enterprise Linux 9

PostgreSQL is a free, open-source, and advanced relational database management system. It is written in C and was initially released in 1986 at the University of California, Berkeley by Michael Stonebraker.

Like other relational databases, it stores data in tables, rows, and columns and uses SQL to read and write data. It is technically an object-relational database which means it can create its custom data types to store objects. During writing, it fully supports ACID transactions. 

The objective of this post is to install PostgreSQL on Red Hat Enterprise Linux 9. 

Prerequisites

  • An instance of RHEL 9
  • Root login or a user with sudo privileges

Install PostgreSQL on Red Hat Enterprise Linux 9

Install PostgreSQL

Run the below command to install PostgreSQL on Red Hat Enterprise Linux 9.

sudo yum install postgresql-server

Initialize database cluster

Run the below command to initialize the database cluster.

sudo postgresql-setup --initdb

Start PostgreSQL service

After you have installed and initialized the postgreSQL database, you can start the database service as follows:

sudo systemctl start postgresql.service

Check the status of PostgreSQL

Run the below command to check if the service has been successfully started or not:

sudo systemctl status postgresql.service

As you can see from the status the PostgreSQL service is installed and running.

Enable PostgreSQL service to run at boot

You can enable PostgreSQL service to run at system boot time. You would run:

sudo systemctl enable postgresql.service

Login to the PostgreSQL server

You can now login to the PostgreSQL server. postgres is the default user with empty password. run the following command:

sudo su -postgres

Enter the sudo password when prompted.

And then type:

psql

Remove PostgreSQL from Red Hat Enterprise Linux 9

Run the command if you would like to remove PostgreSQL from your system.

sudo yum remove postgresql-server

Conclusion

That’s it. We have taught you to install and remove PostgreSQL from Red Hat Enterprise Linux 9. Please support us by sharing this article. Please also read our post to install the MySQL database on Red Hat Enterprise Linux 9.