Install postgreSQL 12 on centOS 8; Through this tutorial, we will learn how to install and use postgreSQL 12 on centOS 8.
PostgreSQL project provides a repository of packages of all supported versions for the most common distributions. Among the distributions supported are all Red Hat family of which includes CentOS, Fedora, Scientific Linux, Oracle Linux and Red Hat Enterprise Linux.
How To Install PostgreSQL 12 on CentOS 8
Just follow the following steps to install and use postgreSQL 12 on centOS 8:
- Step 1 – Add PostgreSQL Yum Repository to CentOS 8
- Step 2 – Install PostgreSQL 12 on CentOS 8
- Step 3 – Initialize and start database service
- Step 4 – Set PostgreSQL admin user’s password
- Step 5 – Enable remote access (Optional)
- Step 6 – Install pgAdmin 4 Web interface
Step 1 – Add PostgreSQL Yum Repository to CentOS 8
First of all, open terminal or command line and execute the following command into it to add postgreSQL yum repository on centOS 8:
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Step 2 – Install PostgreSQL 12 on CentOS 8
Then install PostgreSQL 12 on CentOS 8 by executing the following command on command line or terminal:
sudo dnf -qy module disable postgresql
After that, Install both client and server packages:
sudo dnf -y install postgresql12 postgresql12-server
Step 3 – Initialize and start database service
Before service can be started, first of all, we need to initialize database by executing the following command on command line or terminal:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Execute the following command to start and enable the database server service:
sudo systemctl enable --now postgresql-12
Then run Firewall service and remote clients should connect to your database server, allow PostgreSQL service:
sudo firewall-cmd --add-service=postgresql --permanent sudo firewall-cmd --reload
Step 4 – Set PostgreSQL admin user’s password
Now, execute the following command on command line or terminal to set postgreSQL admin user:
$ sudo su - postgres ~]$ psql -c "alter user postgres with password 'StrongPassword'" ALTER ROLE
Step 5 – Enable remote access (Optional)
Edit the file /var/lib/pgsql/12/data/postgresql.conf
and set Listen address to your server IP address or “*” for all interfaces:
listen_addresses = '192.168.10.10'
Also set PostgreSQL to accept remote connections
$ sudo vim /var/lib/pgsql/12/data/pg_hba.conf # Accept from anywhere host all all 0.0.0.0/0 md5 # Accept from trusted subnet host all all 192.168.18.0/24 md5
Restart database service after committing the change.
sudo systemctl restart postgresql-12
Connecting to remote database:
$ psql -U <dbuser> -h <serverip> -p 5432 <dbname>
Step 6 – Install pgAdmin 4 Web interface
Just use the following article guide to installation of pgAdmin4 on CentOS.
Recommended:- How To Install pgAdmin 4 on CentOS 8
Conclusion
Install postgreSQL 12 on centOS 8; Through this tutorial, we have learned how to install and use postgreSQL 12 on centOS 8.