Search

Step-by-Step Guide: How to Install PostgreSQL on AlmaLinux 9

Welcome to our PostgreSQL installation guide for AlmaLinux 9! If you're looking to set up PostgreSQL, an object-relational database management system, on your AlmaLinux 9 server, you've come to the right place. In this tutorial, we'll walk you through each step of the installation process, ensuring a smooth and successful setup.

Before we dive in, let's quickly go over what you can expect from this guide. First, we'll cover the prerequisites you need to have in place before you begin the installation. Then, we'll break down the installation process into clear and easy-to-follow steps. Along the way, we'll provide detailed instructions and explanations to help you understand each action you need to take.

Once PostgreSQL is installed, we'll show you how to set the user password and enable remote access. We'll also guide you on accessing the PostgreSQL console, where you can interact with your newly installed database. Finally, we'll walk you through the process of verifying the installation to ensure everything is working correctly.

By the end of this tutorial, you'll have PostgreSQL up and running on your AlmaLinux 9 server. So, let's get started with the installation process and discover how to unlock the full potential of PostgreSQL on AlmaLinux 9!

Prerequisites

Before proceeding with the installation of PostgreSQL on AlmaLinux 9, there are a few prerequisites that you need to ensure are in place. First and foremost, you should have a server running AlmaLinux 9 as the operating system. Without AlmaLinux 9, you won't be able to install PostgreSQL. Additionally, you will need user privileges with either root access or sudo privileges. This will allow you to execute the necessary commands during the installation process.

Having these prerequisites in place will ensure a smooth and successful installation of PostgreSQL on AlmaLinux 9, so make sure you have them sorted before moving forward.

Prerequisites:

  • AlmaLinux 9 server
  • User privileges with root access or sudo privileges

Ensure that you have a server running AlmaLinux 9 as the operating system, and user privileges with either root access or sudo privileges.

Step 1. Update the System

Before installing PostgreSQL on AlmaLinux 9, it is important to update the system to ensure that you have the latest package versions. Updating the system helps to improve security and stability, and ensures compatibility with the latest software releases. To update the system, follow these steps:

  1. Open the terminal on your AlmaLinux 9 system.
  2. Run the command dnf update to update the packages. This command will fetch the latest package information and update any installed packages with newer versions.
  3. After the update is complete, you can use the command dnf upgrade to upgrade any packages that have newer versions available. This step is optional but recommended to ensure that all packages are fully up to date.

It is important to regularly update your system to ensure that you have the latest security patches and bug fixes. By keeping your system up to date, you can maintain the stability and performance of your PostgreSQL installation.

Once you have updated your AlmaLinux 9 system, you are ready to proceed with the installation of PostgreSQL.

Step 2. Install PostgreSQL

Now that you have updated the system, it's time to install PostgreSQL on your AlmaLinux 9 server. The installation process involves adding the official PostgreSQL repository for AlmaLinux 9 and installing the PostgreSQL server.

  1. Adding the PostgreSQL repository: Use the command dnf install followed by the repository RPM to add the official PostgreSQL repository to your AlmaLinux system.
  2. Updating the package index: Run the command dnf update to update the local package index with the latest available packages.
  3. Installing the PostgreSQL server: Finally, use the command dnf install followed by the package name to install the PostgreSQL server on your system.

Once the installation is complete, you will have PostgreSQL up and running on your AlmaLinux 9 server. Congratulations!

Next, you can proceed to the next step and set the PostgreSQL user password, which is recommended for security purposes.

Quick Tip:

If you encounter any issues during the installation process, refer to the official PostgreSQL documentation for troubleshooting guidance. Their documentation provides detailed explanations and solutions to common problems.

Step 3: Set the PostgreSQL User Password

After successfully installing PostgreSQL on your AlmaLinux 9 server, it is important to set a password for the PostgreSQL user. This will help ensure the security and integrity of your database. To set the password, follow these steps:

  1. Open a terminal or command prompt and log in as the root user or use the "sudo" command.
  2. Type the following command to change the password for the PostgreSQL user:

passwd postgres

  1. You will be prompted to enter the new password. Type your desired password and press Enter.
  2. Retype the password when prompted to confirm.

Once you have completed these steps, the PostgreSQL user password will be set, adding an extra layer of security to your database.

Remember:

It is important to choose a strong password that includes a combination of uppercase and lowercase letters, numbers, and special characters. Additionally, make sure to store your password securely and avoid sharing it with unauthorized individuals.

Step 4: Allowing Remote Access

To enable remote access to your PostgreSQL database on AlmaLinux 9, you need to make a few configuration changes. By default, PostgreSQL is set to listen only on the localhost, which means it can only be accessed from the local machine. To allow remote access, you'll need to modify the PostgreSQL configuration files.

First, open the "postgresql.conf" file and locate the line that says "listen_addresses = 'localhost'". Replace 'localhost' with '*', so the line now reads "listen_addresses = '*'". This change tells PostgreSQL to listen on all network interfaces.

Note: Be cautious when allowing remote access as it can introduce security risks. Make sure to restrict access to trusted IP addresses or networks.

Next, open the "pg_hba.conf" file and add the following line at the end: "host all all 0.0.0.0/0 md5". This line allows all IP addresses to connect to the database with password authentication. If you want to restrict access to a specific IP address or network, replace "0.0.0.0/0" with the appropriate IP range.

Restarting the PostgreSQL Service

Once you've made the necessary changes to the configuration files, save them and restart the PostgreSQL service for the modifications to take effect. You can do this by running the command "systemctl restart postgresql-14" as the root user or with sudo privileges.

With remote access enabled, you can now connect to your PostgreSQL database from anywhere using a PostgreSQL client or a programming language library. Remember to secure your database by following best practices for authentication and access control.

Step 5: Accessing the PostgreSQL Console

After successfully installing PostgreSQL on your AlmaLinux 9 server, you can now access the PostgreSQL console to interact with the database. The PostgreSQL console provides a command-line interface where you can execute SQL queries, create new users and databases, and perform various administrative tasks.

To access the PostgreSQL console, open your terminal and run the following command:

sudo -u postgres psql

This command grants you the necessary privileges to access the PostgreSQL console as the postgres user. Once you run the command, you will be greeted with the PostgreSQL command prompt, indicating that you are now connected to the database.

From the PostgreSQL console, you can start executing SQL queries to interact with your databases. For example, you can create tables, insert data, perform updates, and retrieve information using the SQL syntax.

Verifying the Installation

Once you have successfully installed PostgreSQL on AlmaLinux 9, it's important to verify the installation to ensure everything is working correctly. You can do this by checking the PostgreSQL version and the status of the PostgreSQL service.

To check the PostgreSQL version, you can use the following command in the terminal:

psql -V

This command will display the installed version of PostgreSQL on your AlmaLinux 9 system.

Additionally, you can check the status of the PostgreSQL service by running the following command:

systemctl status postgresql-14

This command will provide information about the running status of the PostgreSQL service. It will show whether the service is active and running properly.

By verifying the installation and checking the PostgreSQL version and service status, you can ensure that your PostgreSQL installation on AlmaLinux 9 is functioning as expected.

Conclusion

Congratulations! You have successfully installed PostgreSQL on AlmaLinux 9. This step-by-step guide has walked you through the process of updating the system, installing PostgreSQL, setting the user password, allowing remote access, and accessing the PostgreSQL console.

Now you have the power to store and manage structured and unstructured data using PostgreSQL. With its robust features and scalability, PostgreSQL proves to be a reliable choice for your database management needs on AlmaLinux 9.

Remember, this guide provides a summary of the installation process. For more detailed information and advanced configurations, be sure to refer to the official PostgreSQL documentation. Enjoy exploring the possibilities with PostgreSQL on AlmaLinux 9!

Sys Admin

Sys Admin

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