Skip to content

Instantly share code, notes, and snippets.

@Sharifur
Created June 5, 2024 10:49
Show Gist options
  • Save Sharifur/08375da3a9f052b16f785f041698409c to your computer and use it in GitHub Desktop.
Save Sharifur/08375da3a9f052b16f785f041698409c to your computer and use it in GitHub Desktop.
How to Install PostgreSQL 16 on AlmaLinux
https://www.liquidweb.com/kb/install-postgresql-almalinux/
Install PostgreSQL on AlmaLinux
If you have never installed PostgreSQL on Linux before, or this is your first time using AlmaLinux, don’t worry. Just follow our easy five-step guide to get PostgreSQL running in no time.
Step #1: Update AlmaLinux
Before you install PostgreSQL on Linux, you should first make sure that your distribution has the latest packages installed. To do this, you need to use the dnf command, which will automatically update any outdated packages.
dnf update -y
Here is the output.
Step #2: Install PostgreSQL
The latest version of PostgreSQL is not available in the AlmaLinux default repository. That’s why, in order to install the latest version of PostgreSQL, you will need to manually download PostgreSQL for Linux from its official repository. Use the following command to achieve this.
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Here is the output.
Note:
For users on AlmaLinux 8, please be aware that postgresql15 and postgresql15-server are not accessible by default. To enable their availability, it is necessary to first disable the built-in module of PostgreSQL. Execute the following command to achieve this: dnf -qy module disable postgresql.
Now install the PostgreSQL 15 client and server with the following command.
dnf install -y postgresql15 postgresql15-server
Here is the output.
Once the installation is complete, you can initialize the PostgreSQL database. Use the following command to achieve this.
/usr/pgsql-15/bin/postgresql-15-setup initdb
Here is the output.
Finally, you should start and enable the PostgreSQL service with the following command. This command will run PostgreSQL and set it to load at boot.
systemctl enable postgresql-15 && systemctl start postgresql-15
Here is the output. Note that successfully running the command gives the message Created symlink along with the file paths.
Step #3: Set a Password
You can now set a password for the default postgres user. For maximum security, make sure to use a long string of uppercase letters, lowercase letters, numbers, and symbols. Securing the database server is critical for your application’s or website’s overall security.
Use the command below to set the password. You will be asked to retype it one more time.
passwd postgres
Here is the output.
After you have set the password for the Postgres user, you will have to use it every time you need to access PostgreSQL.
Step #4: Enable Remote Access
Since you will likely be using PostgreSQL as a server, you will need to enable remote access for it. This is because it is set to localhost by default. To enable remote access, follow these next steps.
First, open the /var/lib/pgsql/15/data/postgresql.conf file and replace listen_addresses = 'localhost' with listen_addresses = '*'.
Here you see the unchanged file.
Then, open the /var/lib/pgsql/15/data/pg_hba.conf file and add the following entry to the end of it.
host all all 0.0.0.0/0 md5
Again, here is the unchanged file you will add this line to.
Finally, restart the postgreSQL service to apply the changes. Use the following command to achieve this.
systemctl restart postgresql-15
Step #5: Open the Console
To open the PostgreSQL console, use the following command.
sudo -u postgres psql
Here is the output.
You managed to install PostgreSQL on AlmaLinux.
Final Thoughts
Installing PostgreSQL on AlmaLinux does not have to be difficult. This guide walks through the installation requirements as well as installing and running PostgreSQL on Almalinux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment