How to Install PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9

9 Min Read

Introduction to Install PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9

PostgreSQL 15 represents a significant advancement in the evolution of open-source relational database management systems. This version introduces various enhancements, including improved performance, enhanced security features, and greater flexibility in handling complex queries. Key improvements in PostgreSQL 15 include the introduction of SQL/JSON path expressions, enhanced partitioning capabilities, and optimized query performance, making it an ideal choice for modern data-driven applications.

AlmaLinux 9 and Rocky Linux 9 are both community-driven, enterprise-grade Linux distributions designed to provide long-term stability and security. These operating systems emerged as successors to CentOS, offering a reliable and secure platform for running critical applications and services. Both AlmaLinux and Rocky Linux are compatible with Red Hat Enterprise Linux (RHEL), ensuring robust performance and extensive support from a wide range of software vendors.

Choosing the right operating system is crucial for efficient database management. AlmaLinux 9 and Rocky Linux 9, with their focus on stability and security, provide an excellent foundation for running PostgreSQL 15. These distributions offer a consistent and predictable environment, which is essential for maintaining the integrity and performance of database systems. Additionally, their compatibility with RHEL ensures extensive documentation and support, facilitating smooth installation and maintenance processes.

Running PostgreSQL 15 on AlmaLinux 9 or Rocky Linux 9 offers several benefits. The enhanced performance and security features of PostgreSQL 15 are well-supported by the robust architecture of these Linux distributions. Users can leverage the advanced capabilities of PostgreSQL 15 to handle large datasets, perform complex queries efficiently, and ensure data integrity and security. Moreover, the strong community support for both AlmaLinux and Rocky Linux ensures timely updates and patches, further enhancing the reliability of the database environment.

In summary, PostgreSQL 15, with its array of new features and improvements, combined with the stability and security provided by AlmaLinux 9 and Rocky Linux 9, creates a powerful and reliable solution for modern database management needs.

Prerequisites and System Preparation

Before proceeding with the installation of PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9, it is crucial to ensure that your system meets the necessary prerequisites and is properly prepared. This preparation includes updating the system, installing essential tools, and verifying system requirements.

Firstly, verify that your system has the required resources to run PostgreSQL 15 efficiently. A minimum of 1GB of RAM and 1GB of disk space is recommended, although more may be necessary depending on your workload and database size.

Next, update your system packages to ensure that all software is up-to-date. This can be done by running the following commands:

sudo dnf update -y

This command will refresh your repository cache and update all installed packages to their latest versions, which is a critical step for ensuring compatibility and stability.

Following the system update, install essential tools such as ‘wget’ or ‘curl’, which are necessary for downloading files from the internet. These tools can be installed using the following commands:

sudo dnf install wget -y

or

sudo dnf install curl -y

These utilities are fundamental for various system operations and will be particularly useful during the PostgreSQL installation process.

Additionally, it is advisable to install other essential utilities such as ‘vim’ or ‘nano’ for text editing, and ‘net-tools’ for network management, using:

sudo dnf install vim nano net-tools -y

Setting up a proper system environment also involves configuring firewall rules if you plan to access PostgreSQL remotely. Ensure that the firewall allows traffic on the PostgreSQL default port (5432). You can achieve this by executing:

sudo firewall-cmd --add-service=postgresql --permanent

sudo firewall-cmd --reload

By completing these steps, you will have a well-prepared system environment that is ready for the installation of PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9.

Installing PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9

To begin the installation of PostgreSQL 15 on AlmaLinux 9 and Rocky Linux 9, it is essential to add the PostgreSQL repository to the system and update the package list. Follow these steps carefully:

First, add the PostgreSQL repository by executing the following command:

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

Next, disable the built-in PostgreSQL module to ensure that the system uses the repository we just added:

sudo dnf -qy module disable postgresql

Update the package list to incorporate the new repository:

sudo dnf update

Now, proceed with the installation of PostgreSQL 15 using the package manager:

sudo dnf install -y postgresql15-server

After successfully installing PostgreSQL 15, initialize the database by running:

sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

Once initialized, start the PostgreSQL service:

sudo systemctl start postgresql-15

To ensure that PostgreSQL starts automatically on boot, enable the service:

sudo systemctl enable postgresql-15

Verify the installation by checking the status of the PostgreSQL service:

sudo systemctl status postgresql-15

If the service is running correctly, the status should show as “active (running).” This confirms that PostgreSQL 15 has been installed and is operational on your AlmaLinux 9 or Rocky Linux 9 system.

These steps ensure a smooth installation process, enabling you to utilize PostgreSQL 15 for your database management needs.

Post-Installation Configuration and Testing

Upon successfully installing PostgreSQL 15 on AlmaLinux 9 or Rocky Linux 9, several initial configuration tasks are essential for optimal performance and security. Begin by setting up the PostgreSQL user and database. By default, PostgreSQL uses the ‘postgres’ user. Switch to this user to start configuring your database environment:

sudo -i -u postgres

Next, create a new PostgreSQL user and a database. Replace ‘yourusername’ and ‘yourdatabase’ with your preferred usernames and database names:

createuser --interactive

createdb yourdatabase

Configuring the authentication method is crucial. Open the ‘pg_hba.conf’ file located in the data directory (usually ‘/var/lib/pgsql/15/data/’) and set the authentication method. For example, to use MD5 encryption for password authentication, modify the relevant lines as follows:

host all all 0.0.0.0/0 md5

To enhance performance and security, adjust the ‘postgresql.conf’ file. This file is also located in the data directory. Key parameters to consider include:

listen_addresses = '*'# Allow remote connections

max_connections = 100# Increase if necessary

shared_buffers = 128MB# Adjust based on available memory

After making these changes, restart the PostgreSQL service to apply them:

sudo systemctl restart postgresql-15

Testing your PostgreSQL installation is the next step. Connect to the PostgreSQL server using the ‘psql’ command-line tool:

psql -U yourusername -d yourdatabase

Once connected, create a sample table to ensure that everything is functioning correctly:

CREATE TABLE test_table (id SERIAL PRIMARY KEY, name VARCHAR(50));

INSERT INTO test_table (name) VALUES ('Sample Data');

SELECT * FROM test_table;

For additional security, set strong passwords for all database users and configure your firewall to allow only trusted IP addresses to access the PostgreSQL port (default 5432). Use the following commands to enable the firewall:

sudo firewall-cmd --add-service=postgresql --permanent

sudo firewall-cmd --reload

These steps ensure a robust and secure PostgreSQL installation, ready for production use.

Leave a comment