Installing PostgreSQL on CentOS 8
In this tutorial, we will learn how to install PostgreSQL on CentOS 8/ RHEL 8.
PostgreSQL 13 is the latest version, which you can install on CentOS by running the following set commands as root at the command prompt:
sudo dnf -qy module disable postgresql sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo dnf install -y postgresql13-server
You have successfully installed PostgreSQL on your CentOS computer. Now run the following to start and enable CentOS
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable postgresql-13 sudo systemctl start postgresql-13
How it Works…
A version of PostgreSQL ships with CentOS default software repository. However, it is not the latest version. To get the latest version, we need to set up PostgreSQL DNF Repository.
We started by disabling the default PostgreSQL package:
sudo dnf -qy module disable postgresql
Next, we installed the DNF Repository by running the following command:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
To install PostgreSQL 13, we executed the following command:
sudo dnf install -y postgresql13-server
There are a couple of different versions of PostgreSQL available. You can run the following command to get a list of all available versions:
dnf search postgresql | grep -i server
Getting to Know Your Cluster
A new Linux user called
postgres was created during the installation. This Linux user is the superuser of the Postgres Cluster.
postgres user does not have a password, hence you need to log in to the user account using root privileges as follows:
su - postgres
postgres user can log in to the Postgres shell using the
psql command without a password.
PostgreSQl 13 was installed to
/var/lib/pgsql/13 directory. The
/var/lib/pgsql/13/data/postgresql.conf is the main configuration file of the CentOS 8 PostgreSQl 13 cluster.
/var/lib/pgsql/13/data directory, the
/base/ directory is where all of our databases will actually be stored.