Learn how to install PostgreSQL on CentOS 8 with this step-by-step guide. Follow our comprehensive tutorial to set up and configure Postgres on your Linux system quickly and easily. #centlinux #linux #postgres
PostgreSQL Server, often referred to as Postgres, is a highly versatile and feature-rich database management system. It has been actively developed and maintained by a global community of developers for over two decades. Some key features of PostgreSQL include:
PostgreSQL is used by a wide range of organizations, from startups to large enterprises, due to its reliability, flexibility, and strong community support. It is an excellent choice for applications requiring complex queries, high transaction throughput, and strong data integrity guarantees.
Recommended Online Training: PostgreSQL Database Administration on Windows/Linux- Part 2
pgAdmin is a comprehensive and feature-rich open-source management tool for PostgreSQL, a powerful relational database management system. Designed to simplify database management and operations, pgAdmin provides a graphical user interface (GUI) that allows users to interact with PostgreSQL databases more intuitively. Key features of pgAdmin include:
pgAdmin is widely used by database administrators, developers, and analysts for managing PostgreSQL databases efficiently. Its rich set of features and user-friendly design make it an essential tool for anyone working with PostgreSQL.
Just like PostgreSQL, pgAdmin is also a free software. It is also distributed under PostgreSQL license.
Read Also: How to install PostgreSQL on Rocky Linux 9
We are using a minimal CentOS 8 virtual machine with following specifications.
Use a ssh client and login to postgres-01.centlinux.com as root user.
Update Linux server packages by using dnf command.
# dnf update -y Last metadata expiration check: 0:00:58 ago on Sun 22 Nov 2020 08:26:21 PM PKT. Dependencies resolved. Nothing to do. Complete!
Our Linux operating system is already up-to-date.
Check the Linux operating system and Kernel version.
# uname -r 4.18.0-193.28.1.el8_2.x86_64 # cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)
Although Postgres database server is available in Linux yum repositories, but to install latest version, we have to add PostgreSQL official yum repository in our Linux server.
# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Disable the PostgreSQL module in standard yum repository by executing following command.
# dnf -qy module disable postgresql
After setting Postgres Official Yum Repository, you can now easily install PostgreSQL on CentOS 8 server by using dnf command.
# dnf install -y postgresql13-server
You need to execute following command once to initialize the Postgres database.
# /usr/pgsql-13/bin/postgresql-13-setup initdb Initializing database ... OK
Enable and start Postgres database service.
# systemctl enable --now postgresql-13 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service â /usr/lib/systemd/system/postgresql-13.service.
Check the status of Postgres database service.
# systemctl status postgresql-13.service
Check the version of installed PostgreSQL server.
# psql -V psql (PostgreSQL) 13.1
Switch to postgres user and connect to psql shell to set admin user password.
# su - postgres $ psql psql (13.1) Type "help" for help. postgres=# ALTER USER postgres WITH PASSWORD '123'; ALTER ROLE postgres=# q $ exit logout
PostgreSQL default service port is 5432/tcp. Execute the following command to verify that PostgreSQL service is listening on this port.
# ss -tulpn | grep 5432 tcp LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* users:(("postmaster",pid=1603,fd=7)) tcp LISTEN 0 128 [::1]:5432 [::]:* users:(("postmaster",pid=1603,fd=6))
As you may notice that the PostgreSQL service is initially runs on localhost interface only. However, to make our Postgres database available for network clients, you have to configure PostgreSQL to run on all (or on some specific) interfaces.
For this purpose, you have to edit PostgreSQL configuration file in vim text editor.
# vi /var/lib/pgsql/13/data/postgresql.conf
Search for following directive therein.
# listen_addresses = 'localhost'
And replace it with the following directive.
listen_addresses = '*'
Your Postgres database service is now configured to listen on all network interfaces.
Allow network clients to access PostgreSQL service in pg_hba.conf file.
# echo "host all all 192.168.116.0/24 md5" >> /var/lib/pgsql/13/data/pg_hba.conf
Restart Postgres database service to apply changes.
# systemctl restart postgresql-13.service
Again check the network services by using ss command.
# ss -tulpn | grep 5432 tcp LISTEN 0 128 0.0.0.0:5432 0.0.0.0:* users:(("postmaster",pid=1781,fd=6)) tcp LISTEN 0 128 [::]:5432 [::]:* users:(("postmaster",pid=1781,fd=7))
Postgres Service is now running on all network interfaces.
In CentOS 8, we already have a firewall service for PostgreSQL, therefore we are allowing it by using firewall-cmd command. However, you can create a custom firewall service of your own, if your PostgreSQL server is configured to listen on a non-default port.
# firewall-cmd --permanent --add-service=postgresql success # firewall-cmd --reload success
Postgres database server has been installed on Linux server.
pgAdmin is a popular web interface for database administration of PostgreSQL databases.
Although pgAdmin is also provided within PostgreSQL official yum repositories. But it doesn’t work on our CentOS 8 server.
Therefore, we are installing the latest stable version of pgAdmin from pgAdmin official yum repository.
For this purpose, first you need to remove the PostgreSQL yum repositories from your Linux server.
# dnf remove -y pgdg-redhat-repo
Now, add the pgAdmin official yum repository in your Linux operating system.
# dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm
You are also required to install EPEL (Extra Packages for Enterprise Linux) yum repository, because pgAdmin requires some software packages that are not available in standard yum repositories.
Use dnf command and install EPEL yum repository.
# dnf install -y epel-release
Build cache for newly installed yum repositories.
# dnf makecache CentOS-8 - AppStream 2.1 kB/s | 4.3 kB 00:02 CentOS-8 - Base 3.7 kB/s | 3.9 kB 00:01 CentOS-8 - Extras 768 B/s | 1.5 kB 00:02 Extra Packages for Enterprise Linux Modular 8 - 24 kB/s | 98 kB 00:04 Extra Packages for Enterprise Linux 8 - x86_64 92 kB/s | 8.3 MB 01:32 pgadmin4 1.1 kB/s | 2.9 kB 00:02 Metadata cache created.
All repositories has been added. You can now install pgAdmin by using dnf command.
# dnf install -y pgadmin4
To configure SELinux policies, the pgAdmin setup requires semanage command, which is provided in policycoreutils-python-utils packages. Therefore, you should install it before executing pgAdmin setup script.
# dnf install -y policycoreutils-python-utils
The pgAdmin software comes with a well written configuration script to configure pgAdmin web service. Execute it to create a admin user, configure SELinux policies and Apache web server to deploy pgAdmin web service.
# /usr/pgadmin4/bin/setup-web.sh Setting up pgAdmin 4 in web mode on a Redhat platform... Creating configuration database... NOTE: Configuring authentication for SERVER mode. Enter the email address and password to use for the initial pgAdmin user account: Email address: ahmer@postgres-01.centlinux.com Password: Retype password: pgAdmin 4 - Application Initialisation ====================================== Creating storage and log directories... Configuring SELinux... The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? y Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service. Apache successfully enabled. Apache successfully started. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4
The above script installs a configuration file (/etc/httpd/conf.d/pgadmin4.conf) to deploy pgAdmin on Apache web server.
No customization is required in this file. You are only required to enable and start httpd service.
# systemctl enable --now httpd.service Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service.
Configure Linux firewall to allow incoming traffic to Apache web server.
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
Open URL http://postgres-01.centlinux.com/pgadmin4/ in a web browser.
Login to pgAdmin as admin user that we have created by setup-web.sh script.
After successful login, you may reach at the pgAdmin dashboard.
To add your PostgreSQL database server in pgAdmin inventory, click on “Add New Server”.
Provide the Server name and click on “Connection” tab.
Provide the database connection information in this dialog box as we did in the above screenshots.
Click on “Save”.
Our Postgres database server has been added in pgAdmin. You can see a tree of you database server in the left side panel.
For learning more about Postgres databases, we recommend that you should read Learn PostgreSQL: Build and manage high-performance database solutions using PostgreSQL 12 and 13 (PAID LINK) by Packt Publishing
In conclusion, installing PostgreSQL on CentOS 8 can be straightforward if you follow the right steps. PostgreSQL is a robust, feature-rich database management system, and setting it up correctly ensures you can leverage its full potential for your applications.
If you need further assistance with installing PostgreSQL on Linux or any other database-related tasks, I’m here to help. Check out my Fiverr service for professional and reliable support: Linux Server Admin. I offer step-by-step guidance and expert advice to ensure your PostgreSQL installation and configuration are done right. Let’s get your database up and running smoothly!
Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
This website uses cookies.