Install PostgreSQL in CentOS 8 - Step by Step Process ?

Are you trying to install PostgreSQL on CentOS system?

This guide will help you.

PostgreSQL, also known as Postgres, is a relational database management system that provides an implementation of Structured Query Language, better known as SQL. 

It's used by many popular projects, both large and small, is standards-compliant, and has many advanced features like reliable transactions and concurrency without read locks.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform PostgreSQL installation tasks on their Linux System.

In this context, we shall look into how to install PostgreSQL on CentOS 8 Linux distribution.

How to install PostgreSQL databases on CentOS 8 ?

To begin, You should be login as the root user or you must have privileges to run the 'sudo' command on your system.

Then, open the command line application 'Terminal' by clicking on the terminal icon from the left sidebar of your desktop. 

Execute the below-mentioned command to log in on your terminal as the root user:

$ su

You will be prompted to enter the root account password.

Now, you can run all the administrative commands for PostgreSQL installation.

To complete the installation of PostgreSQL on CentOS 8, you will implement the following steps.

1. Update system cache

It is a recommended and quite an easy step that you should update the repository cache of your system repository or packages by using the following command:

$ dnf makecache

2. Install PostgreSQL

All package has been updated. Now, execute the below-given command to install the PostgreSQL server on your system:

$ dnf install postgresql postgresql-server

During the installation, you need to press 'y' and then hit the 'Enter' key to confirm the installation of PostgreSQL.

The complete status will display on the terminal that represents the installation of PostgreSQL has been completed.

3. Check installed version of PostgreSQL

Once the installation of PostgreSQL is complete, to verify the working of PostgreSQL databases run the below-mentioned command:

$ postgres --version

This command will display the version of PostgreSQl installed on the system.

4. Initialize the PostgreSQL database

To initialize the PostgreSQL database server directory, type the following command on the terminal:

$ postgresql-setup --initdb

5. Enable and Start PostgreSQL services

You can enable the services of PostgreSQL by running the following set of commands:

$ systemctl enable postgresql

To know the services running status, use the below-mentioned commands:

$ systemctl start postgresql
$ systemctl status postgresql

How to uninstall PostgreSQL server from CentOS system ?

If you don't want to use the PostgreSQL database server on your system then, by using the following command you can remove it:

$ dnf remove postgresql postgresql-server

How to Create a new PostgreSQL database ?

To do this, simply Login as root on your PostgreSQL database server by running the command:

$ su

You will be prompted to enter password to login as root.

Then run the command:

# su - postgres

Now, we have created a new PostgreSQL database with the name ‘ibmimediadb’ by using the following command:

$ createdb ibmimediadb

Now, access the created database ‘ibmimediadb’ by using the following command:

$ psql ibmimediadb

To test the working of the above-mentioned database execute the following SQL query:


How to Create Tables in PostgreSQL Database ?

Here, we can create tables and assigned privileges on this database by pasting the following code in your current database shell:


This will create the table with the name ‘users’.

To list all tables or relations of your database run the below-given command:

# \d

To exit from the database type the following command:

# \q

[Need urgent assistance to set up PostgreSQL on your Ubuntu Server? We are available to help you. ]

This article will cover how to install and remove the PostgreSQL server and create a database in PostgreSQL on CentOS 8. Also you will learn how to add tables in the database by using the SQL query.

PostgreSQL is available from CentOS 8's default AppStream software repository, and there are multiple versions which you can install. 

You can choose between these versions by enabling the appropriate collection of packages and dependencies that align with the version you want to install, with each collection referred to as a module stream.

To List out the available streams for the postgresql module using the dnf command:

$ dnf module list postgresql

Related Posts