How To Install PostgreSQL 16 on CentOS 9|8

How To Install PostgreSQL 16 on CentOS 9|8

Install postgreSQL 16 on centOS; Through this tutorial, we will learn how to install and use postgreSQL 16 on centOS 9|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 16 on CentOS 9|8

Just follow the following steps to install and use postgreSQL 16 on centOS 9|8:

Step 1 – Add PostgreSQL Yum Repository to CentOS 8

First of all, open terminal or command line and run the following command into it to add postgreSQL yum repository on centOS 9:

sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

And if you have centOS 9, To add postgreSQL yum repository by using this command:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm 

Step 2 – Install PostgreSQL 16 on CentOS 9|8

Then install PostgreSQL 16 on CentOS 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 install -y postgresql16-server postgresql16-contrib

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-16/bin/postgresql-16-setup initdb

Execute the following command to start and enable the database server service:

sudo systemctl enable --now postgresql-16

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/16/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/16/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-16

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

Conclusion

Through this tutorial, we have learned how to install and use postgreSQL 16 on centOS 8.

Recommended CentOS Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *