Search

Step-by-Step Guide: How to Install PostgreSQL Rocky Linux 9

Welcome to our comprehensive Postgres installation guide for Rocky Linux 9. In this step-by-step tutorial, you will learn how to install PostgreSQL 15 on your Rocky Linux 9 system. PostgreSQL is a powerful, free, and open-source relational database management system that provides robust SQL language support.

To get started with the installation, you will need a minimal installed Rocky Linux 9, at least 2GB RAM and 2 CPU, a sudo user with admin rights, and a stable internet connection. Follow the instructions below to enable the PostgreSQL 15 repository, install PostgreSQL 15, initialize the database, start the PostgreSQL service, and secure your PostgreSQL database.

Let's dive in and begin the process of installing PostgreSQL on Rocky Linux 9!

Prerequisites for PostgreSQL Installation on Rocky Linux 9

Before you start installing PostgreSQL on Rocky Linux 9, there are a few prerequisites that you need to take care of. These prerequisites will ensure a smooth and successful installation process.

  1. Rocky Linux 9: Make sure you have Rocky Linux 9 installed on your system. If you haven't done it yet, follow the installation guide provided by the official Rocky Linux documentation.
  2. Minimum Hardware Requirements: Ensure that your system meets the minimum hardware requirements for running PostgreSQL. You'll need at least 2GB of RAM and 2 CPU cores to ensure optimal performance.
  3. Sudo User: To install PostgreSQL, you need to have a sudo user with administrative privileges. This user will be used to run commands with elevated privileges during the installation process.
  4. Stable Internet Connectivity: A stable internet connection is necessary to download the required packages and dependencies during the installation process. Make sure you have a reliable internet connection before proceeding.

By ensuring that you have these prerequisites in place, you'll be ready to proceed with the installation of PostgreSQL on Rocky Linux 9. It's important to fulfill these requirements to avoid any installation issues and to ensure that PostgreSQL runs smoothly on your system.

Enabling the PostgreSQL 15 Repository on Rocky Linux 9

To install PostgreSQL 15 on Rocky Linux 9, you need to enable the PostgreSQL 15 repository. By enabling the repository, you gain access to the latest version of PostgreSQL and can easily install it on your system. To enable the repository, follow these steps:

  1. Open the terminal on your Rocky Linux 9 system.
  2. Run the following command:

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

  1. This command will download and install the PostgreSQL 15 repository on your system.

Once the repository is enabled, you can proceed with the installation of PostgreSQL 15 on Rocky Linux 9. It is important to have the repository enabled to ensure that you are installing the latest version of PostgreSQL with all the necessary updates and security patches.

Why should you enable the PostgreSQL 15 repository?

Enabling the PostgreSQL 15 repository on Rocky Linux 9 gives you access to the latest features, bug fixes, and security updates for PostgreSQL. By keeping your PostgreSQL installation up to date, you can ensure the stability and security of your database system. Additionally, enabling the repository allows you to easily install and manage PostgreSQL extensions, which can enhance the functionality of your database.

Installing PostgreSQL 15 on Rocky Linux 9

Once you have enabled the PostgreSQL 15 repository on Rocky Linux 9, you can proceed with the installation process. Follow these steps to install PostgreSQL 15:

  1. Update the system by running the command sudo dnf update -y.
  2. Install PostgreSQL 15 server and client by running the command sudo dnf install postgresql15-server -y.

These commands will update the system and install the necessary packages for PostgreSQL 15 on Rocky Linux 9. It may take a few minutes to complete the installation, depending on your internet speed.

Once the installation is finished, you can verify the installed version of PostgreSQL by running the command:

psql -V

This will display the version number of PostgreSQL installed on your Rocky Linux 9 system.

Initializing and Starting PostgreSQL 15 on Rocky Linux 9

Once you have successfully installed PostgreSQL 15 on Rocky Linux 9, the next step is to initialize and start the database. This ensures that the database is set up and ready for use. To initialize the PostgreSQL 15 database, open the terminal and run the command:

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

This command initializes the database with the default configuration settings. Once the initialization is complete, you can start the PostgreSQL service by running the following systemctl commands:

sudo systemctl start postgresql-15

sudo systemctl enable postgresql-15

Verifying the PostgreSQL Service

To verify that the PostgreSQL service is running correctly, you can use the following command:

sudo systemctl status postgresql-15

This command will display the status of the PostgreSQL service, indicating whether it is active or not. If the service is active, you can proceed with using PostgreSQL on Rocky Linux 9.

Securing the PostgreSQL Database on Rocky Linux 9

When installing PostgreSQL on Rocky Linux 9, it's important to take steps to secure your database. By default, a user named "postgres" is created automatically, allowing access without a password. To enhance security, it's necessary to set a password for the "postgres" user. This can be done by executing the following commands in the terminal:

sudo passwd postgres

su - postgres

psql -c "ALTER USER postgres WITH PASSWORD 'your-password';"

Setting a password for the "postgres" user ensures that a password is required to connect to the database, adding an extra layer of protection.

Additionally, it's a good practice to regularly update and apply security patches to your PostgreSQL installation. Keeping your software up to date helps address any vulnerabilities that may be discovered and ensures that you benefit from the latest security improvements.

Best Practices for Securing PostgreSQL on Rocky Linux 9

  • Change default database port: By default, PostgreSQL listens on port 5432. Changing this default port to a different value can help in preventing unauthorized access and adding an extra level of security.
  • Implement strong password policies: Encourage the use of strong, complex passwords for all user accounts, including the "postgres" user. This helps protect against unauthorized access through brute-force attacks.
  • Limit network accessibility: Configure firewall rules to allow connections to the PostgreSQL database only from trusted networks or specific IP addresses to minimize the risk of unauthorized access.
  • Enable SSL encryption: Configure PostgreSQL to use SSL encryption for client-server communications. This ensures that data transmitted between the client and the server is encrypted, enhancing data security.
  • Regularly backup your database: Implement a regular backup strategy to safeguard your data against potential loss or corruption. Regular backups can be crucial in recovering from unforeseen events.

By following these best practices, you can greatly enhance the security of your PostgreSQL database on Rocky Linux 9, protecting your data and ensuring the integrity of your system.

Additional Extensions for PostgreSQL on Rocky Linux 9

If you're looking to enhance the functionality of your PostgreSQL installation on Rocky Linux 9, you can take advantage of a variety of additional extensions. These extensions provide specialized features and capabilities that can greatly benefit your database management tasks. Here are some popular extensions you can consider:

1. postgis_sfcgal

postgis_sfcgal is an extension that adds support for advanced 2D and 3D spatial operations in PostgreSQL. It enables you to perform complex geospatial calculations, such as 3D rendering, geodesic computations, and volumetric analysis. With postgis_sfcgal, you can take your geospatial data analysis to the next level.

2. postgis_raster

postgis_raster is an extension that adds support for storing and analyzing raster data in PostgreSQL. It allows you to work with large-scale imagery and satellite data, perform raster-based analyses, and integrate raster data with your existing spatial datasets. postgis_raster is an essential tool for anyone working with geospatial raster data.

3. postgis_tiger_geocoder

postgis_tiger_geocoder is an extension that provides geocoding capabilities to PostgreSQL. It allows you to convert addresses into geographic coordinates (geocoding) and vice versa (reverse geocoding). With postgis_tiger_geocoder, you can easily integrate location-based services into your applications and perform geospatial analysis based on address data.

4. postgis_topology

postgis_topology is an extension that adds advanced topological operations to PostgreSQL. It enables you to model and analyze complex spatial relationships, such as connectivity, adjacency, and containment. With postgis_topology, you can perform topological queries and ensure the integrity of your spatial data.

To install these extensions, you can use the psql utility and the "CREATE EXTENSION" command. For example, to install the postgis_topology extension for a specific database, you can run the command "psql my_gis_db -c 'CREATE EXTENSION postgis_topology'". Explore these extensions and choose the ones that best fit your PostgreSQL requirements to unlock additional functionality and capabilities.

Conclusion

Installing PostgreSQL on Rocky Linux 9 is a straightforward process that can be accomplished by following this step-by-step installation guide. By ensuring that you meet the necessary prerequisites, enabling the PostgreSQL repository, installing PostgreSQL 15, initializing and starting the database, securing the PostgreSQL database, and optionally installing additional extensions, you can successfully set up and use PostgreSQL on Rocky Linux 9.

PostgreSQL is a powerful and feature-rich RDBMS that offers SQL language support and is widely used in both small and large-scale applications. With its open-source nature, PostgreSQL provides a cost-effective and reliable solution for managing your data.

By following this installation guide, you can leverage the capabilities of PostgreSQL and ensure a smooth experience with your database management. Start exploring the possibilities of PostgreSQL on Rocky Linux 9 now!

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...