Install PostgreSQL 18 on RHEL, Rocky Linux, and AlmaLinux

Install PostgreSQL 18 on RHEL, Rocky Linux, AlmaLinux, Oracle Linux, or CentOS Stream using native packages or PGDG, then initialize and verify the server.

Published

Updated

Read time 20 min read

Reviewed byDeepak Prasad

Install PostgreSQL 18 on RHEL-family Linux using native packages or PGDG, initialize the database cluster, and verify the systemd service

PostgreSQL 18 is available through native distribution repositories on current Enterprise Linux releases. EL 10.2 provides versioned postgresql18-* packages, while RHEL 9.8 provides PostgreSQL 18 through the postgresql:18 module stream. This guide installs the database server on Rocky Linux, RHEL, AlmaLinux, Oracle Linux, and CentOS Stream, initializes a fresh cluster, starts the service, creates an application role and database, and optionally prepares remote access. A separate PGDG procedure is included when native packages are unavailable or when you need the community repository lifecycle.

Tested on: Rocky Linux 10.2 (Red Quartz); PostgreSQL 18.4.

IMPORTANT
Do not run postgresql-setup --initdb over an existing PostgreSQL data directory. If the server already contains PostgreSQL 16 or another major release, use a PostgreSQL major-version upgrade procedure instead of this fresh-install guide.

Prerequisites

  • RHEL, Rocky Linux, AlmaLinux, Oracle Linux, or CentOS Stream with AppStream enabled, or a PGDG repository when native packages are unavailable.
  • sudo command or root access for package installation, cluster initialization, and service management.
  • A fresh host, or a host where the applicable native or PGDG data directory does not already contain a database cluster. The defaults are /var/lib/pgsql/data for native packages and /var/lib/pgsql/18/data for PGDG packages.
  • Outbound network access to distribution or PGDG repositories.

Check the distribution release before you install anything. EL 10.2 provides native versioned PostgreSQL 18 packages, while RHEL 9.8 provides PostgreSQL 18 through a module stream. If PostgreSQL 18 is unavailable natively, check whether PGDG supports your exact distribution, minor release, and architecture.


Choose an install method

Method Best for Jump to
Native distribution packages EL 10.2 with postgresql18-server, RHEL 9.8 with the postgresql:18 module stream, and other releases that publish native PostgreSQL 18 Method 1
PostgreSQL Yum Repository (PGDG) Releases without native PostgreSQL 18, PGDG-only extensions, or organizations that follow the PostgreSQL community packaging lifecycle Method 2

Use native distribution packages for the primary procedure in this guide because PostgreSQL 18 is available directly in current EL 10.2 repositories.

Choose PGDG when:

  • PostgreSQL 18 is unavailable in your installed distribution release
  • A PGDG-only extension is required
  • Versioned binary and service paths are preferred
  • The organization deliberately follows the PostgreSQL community packaging lifecycle

Do not enable PGDG halfway through a native-package installation.

Item Native EL 10.2 Native RHEL 9.8 PGDG (typical)
Install command dnf install postgresql18-server dnf module install postgresql:18/server dnf install postgresql18-server
Setup helper postgresql-setup --initdb postgresql-setup --initdb /usr/pgsql-18/bin/postgresql-18-setup initdb
Service postgresql.service postgresql.service postgresql-18.service
Binary directory /usr/bin /usr/bin /usr/pgsql-18/bin
Data directory /var/lib/pgsql/data /var/lib/pgsql/data /var/lib/pgsql/18/data
postgresql.conf /var/lib/pgsql/data/postgresql.conf /var/lib/pgsql/data/postgresql.conf /var/lib/pgsql/18/data/postgresql.conf
pg_hba.conf /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/18/data/pg_hba.conf

Native distribution streams are not intended for side-by-side installation of multiple PostgreSQL major versions. PGDG is the clearer choice when multiple versioned installations are required, although each cluster still needs its own data directory and port.

Verify paths from the installed RPM with rpm -ql postgresql18-server or rpm -ql postgresql-server, and inspect unit files with systemctl list-unit-files 'postgresql*'.

After installation, continue with verify the server, create a role and database, install extensions, configure remote access, update packages, or uninstall if you need those workflows.


This is the path I tested on Rocky Linux 10.2. Native packages on EL 10.2 and RHEL 9.8 share the same initialization helper, service unit, and default data directory.

Check package availability

Identify the operating system:

bash
cat /etc/os-release

Sample output:

output
NAME="Rocky Linux"
VERSION="10.2 (Red Quartz)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="10.2"
PLATFORM_ID="platform:el10"
PRETTY_NAME="Rocky Linux 10.2 (Red Quartz)"

Confirm the CPU architecture:

bash
uname -m

Sample output:

output
x86_64

Refresh repository metadata without upgrading installed packages. Package discovery, module streams, and installs in this guide use the dnf command.

bash
sudo dnf makecache --refresh

A successful run commonly ends with Metadata cache created. This refreshes metadata for enabled repositories without upgrading the installed operating-system packages.

Platform PostgreSQL 18 native packaging
RHEL 10.2 Versioned postgresql18-* RPM packages
Rocky Linux 10.2 Versioned postgresql18-* RPM packages
AlmaLinux 10.2 Versioned postgresql18-* RPM packages
RHEL 9.8 postgresql:18 module stream
Oracle Linux 10 Verify with dnf info postgresql18-server
CentOS Stream 10 Verify with dnf info postgresql18-server

If PostgreSQL 18 is not available natively, check these common causes:

  • The system has not been updated to the required minor release
  • AppStream is disabled
  • Repository metadata is stale
  • A pinned repository snapshot predates PostgreSQL 18
  • The architecture does not have the expected package build

Exact publication timing can differ between Oracle Linux, CentOS Stream, and RHEL rebuilds.

On RHEL 9 systems, list module streams before you assume a versioned RPM name:

bash
dnf module list postgresql

The postgresql:18 stream should appear on RHEL 9.8. On Rocky Linux, AlmaLinux, or Oracle Linux 9, run dnf module list postgresql first because the available PostgreSQL streams can differ by distribution and minor release.

Install PostgreSQL 18 on EL 10.2 and newer

On EL 10.2 and compatible rebuilds, install the versioned server package from AppStream:

bash
dnf info postgresql18-server

Sample output:

output
Available Packages
Name         : postgresql18-server
Version      : 18.4
Release      : 1.el10_2
Architecture : x86_64
Repository   : appstream
Summary      : The programs needed to create and run a PostgreSQL server

The Repository: appstream line tells you the native distribution package is available on this host.

List related packages before you install:

bash
dnf list --available 'postgresql18*'

Sample output:

output
postgresql18.x86_64                18.4-1.el10_2    appstream
postgresql18-contrib.x86_64        18.4-1.el10_2    appstream
postgresql18-server.x86_64         18.4-1.el10_2    appstream
postgresql18-pgvector.x86_64       0.8.0-1.el10_2   appstream
postgresql18-postgis.x86_64        3.5.3-1.el10_2   appstream

The exact extension list can vary by enabled repositories. On my Rocky Linux 10.2 host, optional packages such as postgresql18-pgvector and postgresql18-postgis appeared in AppStream, while some add-ons such as postgresql18-pg_partman were listed from EPEL.

Install the database server:

bash
sudo dnf install -y postgresql18-server

Sample output:

output
Installed:
  postgresql18-18.4-1.el10_2.x86_64
  postgresql18-private-libs-18.4-1.el10_2.x86_64
  postgresql18-server-18.4-1.el10_2.x86_64
  uuid-1.6.2-65.el10.x86_64
Complete!

dnf also installs the client and shared libraries the server depends on.

Install PostgreSQL 18 on RHEL 9.8 using the module stream

On RHEL 9.8, PostgreSQL 18 is provided through the postgresql:18 module stream rather than a standalone postgresql18-server RPM name.

Install the server profile from that stream:

bash
sudo dnf module install -y postgresql:18/server

On Rocky Linux, AlmaLinux, or Oracle Linux 9, run dnf module list postgresql first because the available PostgreSQL streams can differ by distribution and minor release. After installation, both native methods use the same initialization helper and service unit shown in the next section.

Check the installed server package:

bash
rpm -q postgresql-server

The returned package version should begin with PostgreSQL 18 because the enabled postgresql:18 stream supplies the unversioned RPM name.

Confirm the installed native packages

On EL 10.2, the server RPM is named postgresql18-server. On RHEL 9.8 module installations, the stream usually installs packages such as postgresql-server instead. List installed PostgreSQL packages locally before you assume the EL 10.2 naming pattern.

Check the installed NEVRA and repository source on EL 10.2:

bash
rpm -q postgresql18-server

Sample output on EL 10.2:

output
postgresql18-server-18.4-1.el10_2.x86_64
bash
dnf info --installed postgresql18-server

Sample output:

output
Installed Packages
Name         : postgresql18-server
Version      : 18.4
Release      : 1.el10_2
From repo    : appstream

Optionally install contrib utilities now or later in Install PostgreSQL 18 extensions:

bash
sudo dnf install -y postgresql18-contrib

On RHEL 9.8 module installations, use postgresql-contrib instead of postgresql18-contrib.

Package pattern (EL 10.2) Purpose
postgresql18 Client programs and shared components
postgresql18-server Database server and initialization integration
postgresql18-contrib Additional PostgreSQL-supplied extensions
postgresql18-devel Development files for building client software or extensions
postgresql18-docs PostgreSQL documentation, where provided
postgresql18-postgis PostGIS extension, where available
postgresql18-pgvector Vector extension, where available
postgresql18-pgaudit Audit extension, where available

On RHEL 9.8 module installations, the equivalent names are postgresql, postgresql-server, and postgresql-contrib.

This article stops at discovering extension packages and enabling a basic contrib extension. PostGIS, pgvector, and pgAudit require additional configuration that belongs in their respective guides.

List installed files when you need to confirm paths and integration files. The rpm command covers -q and -ql when you want to inspect what the server package placed on disk.

bash
rpm -ql postgresql18-server | head -20

On RHEL 9.8 module installations:

bash
rpm -ql postgresql-server | head -20

This lists files installed by the server RPM. Use it to confirm the setup helper, systemd integration, server binaries, and packaged support files instead of assuming their locations.

Initialize and start the native PostgreSQL service

Create the first cluster with the native helper:

bash
sudo postgresql-setup --initdb

Sample output:

output
* Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

That command creates:

  • The PostgreSQL data directory
  • postgresql.conf
  • pg_hba.conf
  • Internal system catalogs
  • The postgres, template0, and template1 databases
  • The initial database superuser role named postgres

Cluster locale, encoding, locale provider, and checksum settings are established during initialization. Check these requirements before creating the cluster because changing some of them later requires creating or migrating to another cluster.

PostgreSQL 18 changes worth noting on a fresh cluster:

  • New clusters enable data page checksums by default
  • MD5 password authentication is deprecated
  • New configurations should prefer SCRAM authentication rather than introducing new MD5 password entries

Relocating PGDATA, WAL, or tablespaces belongs in a separate storage article. This guide uses the native default path /var/lib/pgsql/data.

Enable PostgreSQL at boot and start it now. Native and PGDG installs both rely on systemd; the systemctl command covers enable, start, restart, and reload for the PostgreSQL unit.

bash
sudo systemctl enable --now postgresql.service

The service may take a second or two to accept connections on the first start. Check unit state:

bash
systemctl status postgresql.service

Sample output:

output
● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: disabled)
     Active: active (running)
   Main PID: 420858 (postgres)
     CGroup: /system.slice/postgresql.service
             └─420858 /usr/bin/postgres -D /var/lib/pgsql/data

If startup fails, use the journalctl command to inspect recent unit output before changing configuration:

bash
journalctl -u postgresql.service --no-pager -n 50

The output should show the first initialization, permission, configuration, or port-binding error that prevented the service from starting.


Method 2: Install PostgreSQL 18 from the PGDG repository

Use this method only when native distribution packages are unavailable or when you deliberately choose PGDG. Do not mix native initialization commands with PGDG service units.

PGDG officially lists RHEL, Rocky Linux, and AlmaLinux as supported platforms on the PostgreSQL download page. On Oracle Linux or CentOS Stream, verify repository compatibility before installing the packages.

  1. Open the PostgreSQL downloads page and select your distribution release and CPU architecture.
  2. Install the current PGDG repository RPM shown on that page.
  3. On EL 9 systems, disable the distribution PostgreSQL module before installing PGDG packages.
  4. Refresh DNF metadata.
  5. Confirm that postgresql18-server will come from PGDG before you install it.
  6. Install the server and optional contrib packages.
  7. Initialize the cluster with the PGDG versioned helper.
  8. Enable the versioned service unit.

On EL 10 x86_64, the repository RPM currently looks like this:

bash
sudo dnf install -y \
  https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Use the repository-install command generated by the PostgreSQL download page when you are using EL 9, a non-x86_64 architecture, or a different supported platform.

On EL 9 systems, disable the native PostgreSQL module after installing the PGDG repository RPM and before installing PGDG packages:

bash
sudo dnf -qy module disable postgresql

Run this step on EL 9 before installing the PGDG packages. It disables the native PostgreSQL module so that DNF can select the versioned packages supplied by PGDG. Do not run this command on EL 10 because RHEL-family 10 does not use the same module workflow.

Confirm that the PGDG repository is enabled:

bash
dnf repolist --enabled | grep -i pgdg

Sample output:

output
pgdg18    PostgreSQL 18 for RHEL / Rocky / AlmaLinux 10 - x86_64

Refresh metadata after adding the repository:

bash
sudo dnf makecache --refresh

Confirm the server package will come from PGDG before you install it:

bash
dnf info postgresql18-server

The Repository field should identify PGDG, for example pgdg18, rather than appstream.

Install the server and optional contrib packages:

bash
sudo dnf install -y postgresql18-server postgresql18-contrib

Initialize the cluster with the PGDG versioned helper:

bash
sudo /usr/pgsql-18/bin/postgresql-18-setup initdb

Sample output:

output
Initializing database ... OK

The helper creates the PGDG default data directory, usually /var/lib/pgsql/18/data.

Enable the versioned service unit:

bash
sudo systemctl enable --now postgresql-18.service

Verify the installed paths and unit files from the RPM rather than assuming native EL paths:

bash
rpm -ql postgresql18-server | head -20
bash
systemctl list-unit-files 'postgresql*'

Do not use postgresql.service or postgresql-setup --initdb for a PGDG installation unless the installed packages actually provide those native integration tools.

After PGDG installation, continue with the shared sections below for verification, role creation, and extensions.


Verify the PostgreSQL 18 installation

Use the psql and pg_isready commands that match your package source:

Package source psql command pg_isready command
Native sudo -u postgres psql sudo -u postgres pg_isready
PGDG sudo -u postgres /usr/pgsql-18/bin/psql sudo -u postgres /usr/pgsql-18/bin/pg_isready

First, check whether the server is accepting local connections:

bash
sudo -u postgres pg_isready

On PGDG installations, use /usr/pgsql-18/bin/pg_isready instead.

Sample output:

output
/var/run/postgresql:5432 - accepting connections

pg_isready confirms that a PostgreSQL server is responding on the selected socket or address. The SQL checks that follow confirm the actual server version and runtime configuration.

Verify the running server version with SQL, not only the client binary:

bash
sudo -u postgres psql -c 'SELECT version();'

On PGDG installations:

bash
sudo -u postgres /usr/pgsql-18/bin/psql -c 'SELECT version();'

Sample output:

output
PostgreSQL 18.4 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 14.3.1 20251022 (Red Hat 14.3.1-4), 64-bit

Query the running server for its data directory, configuration files, port, and checksum status:

bash
sudo -u postgres psql -c "
SELECT name, setting
FROM pg_settings
WHERE name IN (
    'server_version',
    'data_directory',
    'config_file',
    'hba_file',
    'port',
    'listen_addresses',
    'data_checksums'
)
ORDER BY name;"

On PGDG installations, use /usr/pgsql-18/bin/psql with the same query.

Sample output on a native installation:

output
name       |                 setting
------------------+------------------------------------------
 config_file      | /var/lib/pgsql/data/postgresql.conf
 data_checksums   | on
 data_directory   | /var/lib/pgsql/data
 hba_file         | /var/lib/pgsql/data/pg_hba.conf
 listen_addresses | localhost
 port             | 5432
 server_version   | 18.4
(7 rows)

On PGDG installations, data_directory, config_file, and hba_file should point under /var/lib/pgsql/18/data.

A successful installation should show:

  • Service state active (running)
  • pg_isready reporting that the server accepts connections
  • server_version beginning with 18
  • Data-directory and configuration paths that match the chosen package source

psql --version reports only the client binary on your PATH, which can differ from the running server.


Create the first role and database

Open an administrative psql session as the Linux postgres user:

bash
sudo -u postgres psql

On PGDG installations:

bash
sudo -u postgres /usr/pgsql-18/bin/psql

Create an application login, set its password interactively, and create an owned database:

sql
CREATE ROLE appuser LOGIN;
\password appuser
CREATE DATABASE appdb OWNER appuser;

Sample interaction:

output
CREATE ROLE
Enter new password for user "appuser":
Enter it again:
CREATE DATABASE

Exit with \q.

List roles to confirm appuser exists:

bash
sudo -u postgres psql -c '\du'

On PGDG installations, use /usr/pgsql-18/bin/psql with the same options.

Sample output:

output
Role name |                         Attributes
-----------+------------------------------------------------------------
 appuser   |
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

The database listing should show appuser as the owner of appdb:

bash
sudo -u postgres psql -c '\l appdb'

Sample output:

output
Name  |  Owner  | Encoding | Locale Provider |   Collate   |    Ctype    | Locale | ICU Rules | Access privileges
-------+---------+----------+-----------------+-------------+-------------+--------+-----------+-------------------
 appdb | appuser | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           |

Keep three identities separate:

  • The Linux account named postgres
  • The PostgreSQL superuser role named postgres
  • Application roles such as appuser

Local socket connections often work through peer authentication when the Linux username matches the PostgreSQL role. On the tested Rocky Linux 10.2 native installation, TCP connections to 127.0.0.1 can match an ident rule while local socket connections use peer. Check the generated pg_hba.conf on your system before changing it.


Install PostgreSQL 18 extensions

Installing an extension normally has two stages:

  1. Install the operating-system package
  2. Enable the extension inside each required database

Install contrib packages if they are not already present.

For native EL 10.2 packages:

bash
sudo dnf install -y postgresql18-contrib

For the native RHEL 9.8 module stream:

bash
sudo dnf install -y postgresql-contrib

For PGDG:

bash
sudo dnf install -y postgresql18-contrib

Enable an extension in a database:

bash
sudo -u postgres psql -d appdb -c 'CREATE EXTENSION IF NOT EXISTS pgcrypto;'

On PGDG installations, use /usr/pgsql-18/bin/psql with the same options.

Sample output:

output
CREATE EXTENSION

dnf search looks through package names and descriptions, while dnf list shows package names that match the PostgreSQL prefix for your package source.

For native EL 10.2 and PGDG:

bash
dnf search postgresql18
bash
dnf list --available 'postgresql18*'

For the native RHEL 9.8 module stream:

bash
dnf search postgresql
bash
dnf list --available 'postgresql*'

Inspect extensions known to the server:

bash
sudo -u postgres psql -d appdb -c "
SELECT name, default_version, installed_version
FROM pg_available_extensions
WHERE name IN ('pgcrypto', 'pg_stat_statements')
ORDER BY name;"

On PGDG installations, use /usr/pgsql-18/bin/psql with the same query.

Sample output:

output
name        | default_version | installed_version
--------------------+-----------------+-------------------
 pg_stat_statements | 1.12            |
 pgcrypto           | 1.4             | 1.4
(2 rows)

A blank installed_version means the extension files are available on the server but the extension has not been enabled in appdb.

Requirement Likely package or extension
Cryptographic SQL functions pgcrypto from contrib
Query statistics pg_stat_statements from contrib
Geospatial data PostGIS packages
Vector similarity search pgvector packages
Database auditing pgAudit packages
Procedural Python PL/Python package

On my Rocky Linux 10.2 host, pgcrypto was available from postgresql18-contrib and enabled successfully in appdb.


Configure remote PostgreSQL access (optional)

Skip this section when applications connect only on the local host.

Remote access needs three layers:

  1. PostgreSQL must listen on a network address
  2. pg_hba.conf must authorize the client network
  3. The host firewall must permit TCP port 5432

For native packages, edit:

text
/var/lib/pgsql/data/postgresql.conf
/var/lib/pgsql/data/pg_hba.conf

For PGDG packages, edit:

text
/var/lib/pgsql/18/data/postgresql.conf
/var/lib/pgsql/18/data/pg_hba.conf

Set a specific listen address in postgresql.conf:

text
listen_addresses = '192.0.2.10'

Add a narrow host rule to pg_hba.conf:

text
host    appdb    appuser    192.0.2.0/24    scram-sha-256

Do not use a broad rule such as host all all 0.0.0.0/0 trust.

Validate authentication rules before you rely on them:

bash
sudo -u postgres psql -c "SELECT line_number, type, database, user_name, address, auth_method, error FROM pg_hba_file_rules;"

On PGDG installations, use /usr/pgsql-18/bin/psql with the same query.

Sample output:

output
line_number | type | database | user_name |   address    |  auth_method  | error
-------------+------+----------+-----------+--------------+---------------+-------
         102 | host | {appdb}  | {appuser} | 192.0.2.0/24 | scram-sha-256 |
(1 row)

The rule is syntactically valid when the error column is empty. PostgreSQL's pg_hba_file_rules view is useful for checking authentication-file errors before relying on the new rule.

If you changed listen_addresses, restart PostgreSQL because that parameter is read only during server startup. If you changed only pg_hba.conf, a reload is sufficient.

For native packages after changing listen_addresses:

bash
sudo systemctl restart postgresql.service

For PGDG packages after changing listen_addresses:

bash
sudo systemctl restart postgresql-18.service

When only pg_hba.conf was edited, reload the service. Use postgresql.service for native packages or postgresql-18.service for PGDG:

bash
sudo systemctl reload postgresql.service
bash
sudo systemctl reload postgresql-18.service

Open the default port only when remote access is required. On hosts using firewalld, see the firewalld reference for persistent port rules:

bash
sudo firewall-cmd --permanent --add-port=5432/tcp
sudo firewall-cmd --reload

Confirm PostgreSQL is listening on the expected address with the ss command:

bash
ss -ltn | grep ':5432'

Sample output on a default local-only install:

output
LISTEN 0 200 127.0.0.1:5432 0.0.0.0:*
LISTEN 0 200     [::1]:5432    [::]:*

After you change listen_addresses and pg_hba.conf, the socket list should include the application network address.

Test from a client host with a one-shot query:

bash
psql -h <server-address> -U appuser -d appdb \
  -c 'SELECT current_database(), current_user;'

Sample output:

output
current_database | current_user
------------------+--------------
 appdb            | appuser
(1 row)

An alternate PostgreSQL port may also require an SELinux port-label change. Complete SELinux and TLS configuration belong in dedicated articles.


Update PostgreSQL packages

Update installed PostgreSQL packages for your package source. The wildcard updates the server, client, libraries, and contrib package without naming every installed RPM manually.

Native EL 10.2:

bash
sudo dnf upgrade 'postgresql18*'

Native RHEL 9.8 module stream:

bash
sudo dnf upgrade 'postgresql*'

PGDG:

bash
sudo dnf upgrade 'postgresql18*'

Restart PostgreSQL after a server package update so the running processes use the newly installed server binaries.

For native packages:

bash
sudo systemctl restart postgresql.service
sudo -u postgres psql -c 'SHOW server_version;'

For PGDG packages:

bash
sudo systemctl restart postgresql-18.service
sudo -u postgres /usr/pgsql-18/bin/psql -c 'SHOW server_version;'

This handles minor package updates within PostgreSQL 18. Major-version upgrades from PostgreSQL 16 or another release belong in a dedicated upgrade article, not in this fresh-install guide.


Uninstall PostgreSQL 18

Back up any databases you need before you proceed. The commands below are source-specific.

Native EL 10.2

Stop and disable the service:

bash
sudo systemctl disable --now postgresql.service

Remove the packages:

bash
sudo dnf remove -y postgresql18-server postgresql18-contrib postgresql18

The next command permanently removes every database stored in the native default cluster directory. Run it only when the cluster is no longer required:

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

Native RHEL 9.8 module stream

Stop and disable the service:

bash
sudo systemctl disable --now postgresql.service

Remove the packages:

bash
sudo dnf remove -y postgresql-server postgresql-contrib postgresql

Reset the module after the packages are removed:

bash
sudo dnf module reset -y postgresql

Resetting the module removes the selected PostgreSQL stream state after its packages have been removed.

Delete the native data directory only when the cluster is no longer required:

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

PGDG

Stop and disable the versioned service:

bash
sudo systemctl disable --now postgresql-18.service

Remove the packages:

bash
sudo dnf remove -y postgresql18-server postgresql18-contrib postgresql18

Delete the PGDG data directory only when the cluster is no longer required:

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

Removing PostgreSQL 18 does not require removing the pgdg-redhat-repo package when the same repository is used for other PostgreSQL versions or extensions.

Confirm removal

Check that the service unit and packages are gone:

bash
systemctl status postgresql.service

Sample output:

output
Unit postgresql.service could not be found.

On PGDG installations, also check postgresql-18.service.

bash
rpm -q postgresql18-server

Sample output:

output
package postgresql18-server is not installed

On RHEL 9.8 module installations, check postgresql-server instead.


Troubleshoot installation and connection failures

Symptom Likely cause Direction
postgresql18-server is not found Release older than the required minor version, AppStream disabled, or stale metadata Check /etc/os-release, enabled repositories, and dnf info
dnf module install postgresql:18/server reports no matching stream The system is not on a release that provides the PostgreSQL 18 module Check the OS release and run dnf module list postgresql
postgresql-setup is not found PGDG packages were installed but native-package instructions are being followed Use the PGDG versioned setup helper
postgresql-18.service is not found Native packages were installed instead of PGDG packages Use postgresql.service and inspect installed unit files
PostgreSQL fails to start immediately The cluster was not initialized Run the setup helper appropriate to the package source
Initialization reports a non-empty directory An old or partial cluster already exists Identify the existing data before taking further action
Port 5432 is already in use Another PostgreSQL instance or service is listening Inspect the socket and existing service units
peer authentication failed The Linux username does not match the requested PostgreSQL role Connect as postgres or adjust local authentication deliberately
Password login over TCP fails on localhost Default pg_hba.conf still uses ident for 127.0.0.1 Add a narrow scram-sha-256 host rule and reload
PostgreSQL still listens only on localhost after editing listen_addresses The service was reloaded rather than restarted Restart the applicable PostgreSQL service
Remote connection is refused PostgreSQL is not listening on the network address Check listen_addresses, service state, and sockets
Remote connection times out Firewall or network routing is blocking the port Check firewalld and network reachability
no pg_hba.conf entry appears No matching host authentication rule exists Add a narrow CIDR-based rule and reload
psql --version shows the wrong version A different client binary appears first in PATH Compare client path with SHOW server_version
Extension control file is missing The matching PostgreSQL 18 extension RPM is not installed Locate and install the correct package
PGDG packages have unresolved system-library dependencies The installed EL minor release is outside the currently supported PGDG range Update to a supported minor release and refresh metadata
database files are incompatible with server The service is starting a data directory created by another PostgreSQL major version Check the service, binary path, and PGDATA; use a documented major-upgrade procedure
Native packages conflict with PostgreSQL 16 The distribution supports only one conflicting native package set Use the documented upgrade path or containers

References


Summary

Choose native distribution packages when they are available: postgresql18-server on EL 10.2 or postgresql:18/server on RHEL 9.8. Initialize with postgresql-setup --initdb, start postgresql.service, and verify the running server with SQL rather than psql --version alone. Use PGDG as a separate method when native packages are unavailable, and remove the installation with dnf remove plus deletion of the data directory when you no longer need the cluster.


Frequently Asked Questions

1. How do I install PostgreSQL 18 on RHEL 9.8?

RHEL 9.8 provides PostgreSQL 18 through the postgresql:18 module stream. Install it with sudo dnf module install postgresql:18/server, then initialize the cluster with postgresql-setup --initdb and start postgresql.service.

2. Should I install PostgreSQL 18 from AppStream or PGDG on Rocky Linux 10?

Use native distribution packages when postgresql18-server or the postgresql:18 module stream is available on your release. Use PGDG when PostgreSQL 18 is missing natively, when you need a PGDG-only extension, or when your organization follows the PostgreSQL community packaging lifecycle.

3. Why does psql --version differ from SHOW server_version?

psql --version reports the client binary on your PATH. SHOW server_version reports the running database server. After installation, confirm the server with sudo -u postgres psql -c "SHOW server_version;" rather than relying on the client alone.

4. Can I run postgresql-setup --initdb on a host that already has PostgreSQL 16?

No. postgresql-setup --initdb creates a new cluster and is not a major-version upgrade. If PostgreSQL 16 or another release already owns the applicable data directory, use a documented major-version upgrade path instead of this fresh-install guide.

5. Why does password authentication fail over 127.0.0.1 right after install?

On the tested Rocky Linux 10.2 native installation, TCP connections to localhost can match an ident rule while local socket connections use peer. Check the generated pg_hba.conf on your system before changing it.

6. Which systemd service name should I use?

Native distribution packages use postgresql.service. PGDG packages usually provide postgresql-18.service. Inspect systemctl list-unit-files postgresql* after installation instead of assuming the native unit name.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …