How to Install PostgreSQL on AlmaLinux 10

Published: 2026-06-26
Google AdSense 广告位 (待申请通过后开启)

Introduction

PostgreSQL is a powerful open-source relational database management system known for its reliability, advanced features, and SQL standards compliance. It is widely used for web applications, enterprise systems, and data analytics.

This guide explains how to install PostgreSQL on AlmaLinux 10, initialize the database cluster, start the service, and verify that the installation is working correctly.

Prerequisites

Before installing PostgreSQL, ensure that:

* You are running AlmaLinux 10.

* You have sudo or root privileges.

* Your system packages are up to date.

Update System Packages

Update package metadata:

sudo dnf update -y

Install PostgreSQL

Install PostgreSQL server and client packages:

sudo dnf install postgresql-server postgresql -y
Image-1
Image-1

Verify the installed packages:

rpm -qa | grep postgresql

Initialize the Database

Initialize the PostgreSQL database cluster:

sudo postgresql-setup --initdb

If your AlmaLinux version uses a versioned package, you can first check the installed service or setup script. (Use the command appropriate for your installed version.)

Start and Enable PostgreSQL

Enable PostgreSQL at boot:

sudo systemctl enable postgresql

Start the service:

sudo systemctl start postgresql

Check the service status:

sudo systemctl status postgresql

The service should display **active (running)**.

Verify the Installation

Check the PostgreSQL client version:

psql --version

Switch to the PostgreSQL system user:

sudo -i -u postgres

Open the PostgreSQL shell:

psql
Image-2
Image-2

Exit the shell:

\q

Create a Test Database

Create a database:

CREATE DATABASE testdb;

Display all databases:

\l

Create a Test User

Create a user:

CREATE USER testuser WITH PASSWORD 'StrongPassword';

Grant privileges:

GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;

PostgreSQL Data Directory

The default database files are usually stored under:

/var/lib/pgsql/

To determine the actual data directory:

SHOW data_directory;

Common PostgreSQL Commands

List databases:

\l

Connect to a database:

\c testdb

List tables:

\dt

Display users:

\du

Stop and Restart PostgreSQL

Stop the service:

sudo systemctl stop postgresql

Restart the service:

sudo systemctl restart postgresql

Uninstall PostgreSQL

Remove PostgreSQL packages:

sudo dnf remove postgresql-server postgresql -y

Optionally remove the data directory (this permanently deletes all databases):

sudo rm -rf /var/lib/pgsql
Image-3
Image-3

Conclusion

Installing PostgreSQL on AlmaLinux 10 is straightforward using the DNF package manager. After installation, initialize the database cluster, start the service, create a database, and verify that PostgreSQL is ready for application development.

Related AlmaLinux 10 Tutorials

How to Install Nginx on AlmaLinux 10

How to Install PHP Binaries on AlmaLinux 10

How to Compile Install PHP on AlmaLinux 10

Explore More

Technology Guides →

Southeast Asia Insights →