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 13 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 13 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 13. 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 13 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
Then, disable the PostgreSQL module on CentOS 8.
:~# dnf module disable postgresql
Now, install PostgreSQL 13 on CentOS 8.
:~# dnf install postgresql13-server postgresql13
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/pgsql-13/bin/postgresql-13-setup initdb Initializing database ... OK
With this, we will have already started the initial database. At this point, the PostgreSQL service is not enable, so you can’t use it yet. Then you have to do it.
:~# systemctl enable postgresql-13
Then, if you want PostgreSQL to start along with the system run this command:
:~# systemctl start postgresql-13
To check that everything is going well, check the status of the service:
:~# systemctl status postgresql-13
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
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 it. Of course, if the data will be served on the Internet, then it is necessary to allow all the accesses.
:~# nano /var/lib/pgsql/13/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 = '*'
Then, restart PostgreSQL.
:~# systemctl restart postgresql-13
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
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 13 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.
Trying to install on an AWS RHEL8 instance. No success.
[root@ip-xxxxxxxxxxx ec2-user]# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-rep
o-latest.noarch.rpm
Last metadata expiration check: 0:26:38 ago on Wed 09 Oct 2019 03:07:05 PM UTC.
pgdg-redhat-repo-latest.noarch.rpm 6.5 kB/s | 10 kB 00:01
Package pgdg-redhat-repo-42.0-5.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@ip-xxxxxxxxxxx ec2-user]# dnf install postgresql12
Last metadata expiration check: 0:26:43 ago on Wed 09 Oct 2019 03:07:05 PM UTC.
No match for argument: postgresql12
Error: Unable to find a match
[root@ip-xxxxxxxxxxx ec2-user]# dnf install postgresql12-server postgresql12
Last metadata expiration check: 0:28:56 ago on Wed 09 Oct 2019 03:07:05 PM UTC.
No match for argument: postgresql12-server
No match for argument: postgresql12
Error: Unable to find a match
Any thoughts?
Thanks.
# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 – BaseOS (RPMs) 0.0 B/s | 0 B 00:02
Failed to download metadata for repo ‘rhel-8-for-x86_64-baseos-rpms’
Error: Failed to download metadata for repo ‘rhel-8-for-x86_64-baseos-rpms’