PostgreSQL (often called Postgres) is a powerful, open-source relational database management system (RDBMS). It is known for its scalability, extensibility, and strong compliance with SQL standards.
If you’re running AlmaLinux 9 and need to set up PostgreSQL, you’re in the right place.
In this guide, I’ll walk you through the installation process step by step no stress, just what you need to get it up and running.
Step 1: Update Your System
Before installing anything, let’s make sure your system is up to date. Open a terminal and run:
dnf update & dnf upgrade
This ensures you have the latest security patches and software versions. It’s always a good habit to update before installing new software.
Step 2: Check Available PostgreSQL Versions
AlmaLinux ships with multiple versions of PostgreSQL. To see what’s available, run:
dnf module list postgresql
You’ll get a list of PostgreSQL versions that you can install.
PostgreSQL server 15 and 16 are included in the AppStream components.
So to install PostgreSQL 17 we will need to add the following official repositories:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Disable the default PostgreSQL module once the repository has been added:
dnf -qy module disable postgresql
Step 3: Install PostgreSQL 17
Now, let’s install the PostgreSQL 17 server and some extra tools:
dnf install postgresql17-server postgresql17-contrib
This will pull in all the necessary packages.
Step 4: Initialize the Database
Before we can use PostgreSQL, we need to initialize the database.
Run this command:
/usr/pgsql-17/bin/postgresql-17-setup initdb
This sets up the default database files and configurations as well as the main configuration file /var/lib/pgsql/17/data/postgresql.conf.
Step 5: Start and Enable PostgreSQL 17
Now, let’s start the PostgreSQL 17 service and make sure it runs automatically on system boot:
systemctl enable --now postgresql-17
To check if PostgreSQL is running, use:
systemctl status postgresql-17
If everything is working, you should see a message saying PostgreSQL is “active (running).”
● postgresql-17.service - PostgreSQL 17 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-17.service; enabled; preset: disabled)
Active: active (running)
Docs: https://www.postgresql.org/docs/17/static/
Process: 104278 ExecStartPre=/usr/pgsql-17/bin/postgresql-17-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 104283 (postgres)
Tasks: 7 (limit: 14115)
Memory: 17.7M
CPU: 659ms
CGroup: /system.slice/postgresql-17.service
├─104283 /usr/pgsql-17/bin/postgres -D /var/lib/pgsql/17/data/
├─104284 "postgres: logger "
├─104285 "postgres: checkpointer "
├─104286 "postgres: background writer "
├─104288 "postgres: walwriter "
├─104289 "postgres: autovacuum launcher "
└─104290 "postgres: logical replication launcher "
Step 6: Set a Password for the PostgreSQL 17
User By default, PostgreSQL creates a user called postgres. You’ll want to set a password for it.
Switch to the postgres user with:
su postgres
Then, enter the PostgreSQL shell:
psql
Set a new password by running:
ALTER USER postgres WITH PASSWORD 'your_secure_password';
Replace ‘your_secure_password’ with something strong! Once done, type \q to exit, then exit to return to your regular user.
Step 7: Backup and Restore a Single Database
You can back up and restore a single database using the pg_dump
utility.
For example, to back up a single database named db and generate a backup file named db_backup.sql, run the following command:
su - postgres
pg_dump -d db -f db_backup.sql
You can also restore a single database using psql command.
For example, to restore a single database named db from a backup file named db_backup.sql, run the following command:
su - postgres
psql -d db -f db_backup.sql
Step 8: Allow Remote Connections (Optional)
By default, PostgreSQL only allows local connections. If you need remote access, edit the config file:
nano /var/lib/pgsql/17/data/postgresql.conf
Find this line:
#listen_addresses = 'localhost'
Uncomment it and change it to:
listen_addresses = '*'
Then, edit the authentication settings:
nano /var/lib/pgsql/17/data/pg_hba.conf
Add this line at the bottom (replace 192.168.1.0/24 with your network range):
host all all 192.168.1.0/24 md5
Restart PostgreSQL for changes to take effect:
sudo systemctl restart postgresql
Comments and Conclusion
You’re Done! That’s it. You now have PostgreSQL 17 server running on AlmaLinux 9!
You can start creating databases and working with your applications. If you have any issues, check the logs with:
journalctl -u postgresql-17 --no-pager | tail -50
For additional help or useful information, we recommend you to check the official PostgreSQL 17 documentation.
If you have any questions please leave a comment below.