Install PostgreSQL on AlmaLinux 10

Database

By Jennifer Webb

Updated on Jan 01, 1970

Install PostgreSQL on AlmaLinux 10

Introduction

This tutorial shows how to install PostgreSQL on AlmaLinux 10, initialize the database cluster, start the service, and confirm that the server is responding correctly on a dedicated server.

By the end, you will have a working PostgreSQL installation that starts automatically at boot and can execute a local SQL query from the postgres account.

Prerequisites

  • An AlmaLinux 10 system
  • Root access or a normal administrative user with sudo privileges
  • Network access to download PostgreSQL packages
  • Access to the dedicated server where PostgreSQL will be installed

Tutorial steps

Install PostgreSQL packages

Install the PostgreSQL server and client packages with dnf.

sudo dnf install postgresql-server postgresql -y

This installs the database server components and the psql client used for verification.

Initialize the database cluster

Initialize the default PostgreSQL data directory before starting the service.

sudo postgresql-setup --initdb

This creates the initial database files under /var/lib/pgsql/data.

Start and enable PostgreSQL

Start PostgreSQL now and configure it to start automatically on boot.

sudo systemctl enable --now postgresql

Verification

Confirm that the PostgreSQL service is active and running.

systemctl status postgresql

Verify that the client binaries are installed.

psql --version

Run a local SQL query as the postgres system user to confirm the server accepts connections and returns a version string.

sudo -u postgres psql -c "SELECT version();"

If all three checks succeed, PostgreSQL is installed and operating correctly on AlmaLinux 10.

Troubleshooting

If postgresql-setup --initdb reports that the data directory already exists or is not empty, stop PostgreSQL and review whether an earlier initialization was left behind. A clean reinstall usually requires removing the existing data directory before reinitializing.

If systemctl status postgresql shows a failed service, inspect the status output for the first startup error. Configuration or permission problems typically appear there before the service can bind to its local socket.

If sudo -u postgres psql -c "SELECT version();" fails, confirm that the service is active and that the local data directory was initialized successfully.

Rollback

If you need to remove PostgreSQL and discard the initialized local database files, stop using the service and uninstall the packages.

sudo dnf remove postgresql-server postgresql -y

Then remove the initialized data directory.

sudo rm -rf /var/lib/pgsql/data

This returns the dedicated server to a state without the PostgreSQL packages or cluster data.

Conclusion

You have completed a PostgreSQL installation on AlmaLinux 10 for a dedicated server, started and enabled the service, and verified that the database client and server can communicate locally.

You can now confirm the service state, the installed client version, and a successful SQL version query to know the PostgreSQL setup is working as expected.