How to install PostgreSQL 11 on CentOS 8 / RHEL 8 / Oracle Linux 8?

0
90

PostgreSQL is one of the most popular database management systems in the world. Its robustness, high availability, and ease of installation make it perhaps the most advanced in the world. Despite easy installation, not always many users do. So, in this post, I will show you how to install PostgreSQL 11 on CentOS 8 / RHEL 8 / Oracle Linux 8. In addition, we’ll show you the most basic configurations. At the end of the post, you will have a PostgreSQL installation ready to start working.

Install PostgreSQL 11 on CentOS 8 / RHEL 8 / Oracle Linux 8

Both RHEL 8 and its derivatives include PostgreSQL 10 in their repositories. However, we already have available version 11. And it is recommended to install it because thanks to it, we can enjoy interesting news and improvements in the performance of the application. Important, if we are going to store large quantities of records.

So first, open a terminal session. Or if you are using a server connect to it using ssh.

:~$ ssh [your-user]@[your-host]

Then log in as the root user.

:~$ su
:~#

The best way to install PostgreSQL 11 on CentOS 8, RHEL 8 and Oracle Linux 8 is to add the official PostgreSQL refill. Not only is it easy, but also safe and the possibility to be always up to date.

To do this, run the following command:

:~# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
1.- Add the PostgreSQL repository
1.- Add the PostgreSQL repository

Then, refresh DNF and finally install PostgreSQL 11.

:~# dnf update
:~# dnf install postgresql-server postgresql  postgresql-contrib

After that, let us configure it.

Configure PostgreSQL on CentOS / RHEL 8 / Oracle Linux 8

Initialize PostgreSQL database and start the service

After installing it, the first thing to do is to initialize the database. To achieve this, it is necessary to execute the following command:

:~# /usr/bin/postgresql-setup --initdb
2.- Initializae the database on PostgreSQL
2.- Initialize the database on PostgreSQL

With this, we will have already started the initial database. At this point, the PostgreSQL service is not active, so you can’t use it yet. Then you have to do it.

:~# systemctl start postgresql

Then, if you want PostgreSQL to start along with the system run this command:

:~# systemctl enable postgresql

To check that everything is going well, check the status of the service:

:~# systemctl status postgresql
3.- The PostgreSQL service status
3.- The PostgreSQL service status

As you can see, everything’s fine.

Change the password to the “postgres” user and allow the remote connections

During the installation of PostgreSQL, a new user called postgres is created. The problem is that you do not define a password, so it makes you vulnerable. To avoid problems, it is convenient to create a password.

To do this, just use the Unix passwd command.

:~# passwd postgres
4.- Change the password to the postgres user
4.- Change the password to the postgres user

There you will have to enter the password twice. If both are effective, the final change will be made.

Now, we have to allow access to remote connections. The client must be installed on each of the systems that will access PostgreSQL. It will depend on each operating system.

Then, a good security measure is to specify the hosts that can access. Of course, if the data will be served on the Internet, then it is necessary to allow all the accesses.

:~# nano /var/lib/pgsql/data/postgresql.conf

then searches for the listen_addresses line and places the hosts that can access it. If you allow any access, type ‘*’.

listen_addresses = '[host/IP_adress]'
or
listen_addresses = '*'
5.- Allow the remote connections
5.- Allow the remote connections

Then, restart PostgreSQL.

:~# systemctl restart postgresql

Finally, you have to open the port 5432 on the firewall to allow the connections.

:~# firewall-cmd --add-port=5432/tcp --permanent
success
:~# firewall-cmd --reload
success

Now, you can access to the PostgreSQL shell.

:~# su - postgres
:~# psql
6.- PostgreSQL on CentOS 8 / RHEL 8 / Oracle Linux 8
6.- PostgreSQL on CentOS 8 / RHEL 8 / Oracle Linux 8

Now, you can start to work.

Conclusion

PostgreSQL is one of the best there is for databases. Thanks to its community spirit, it is possible to find a lot of documentation about it. On the other hand, installing version 11 on CentOS 8, RHEL 8 and Oracle Linux 8 is quite simple as you have seen in this post.

Also, you can read how to install Postgresql on Ubuntu 18.04?

Please share this post with your friends and join our Telegram channel.

LEAVE A REPLY

Please enter your comment!
Please enter your name here