Switching PostgreSQL Module Streams on Rocky Linux 9
Rocky Linux 9 installs PostgreSQL 13 by default, but DNF module streams let you enable PostgreSQL 15 from the distribution's own repositories. Here is how to switch safely and verify the result.
09 Oct 2026, 15:55 UTC

Problem: Rocky Linux 9 Installs PostgreSQL 13 by Default
When you run sudo dnf install postgresql-server on a fresh Rocky Linux 9 system, DNF installs PostgreSQL version 13. If your application requires PostgreSQL 15, adding an unrelated third-party repository is one option, but it introduces packages outside the Rocky Linux build system. Rocky Linux 9 includes PostgreSQL 15 as an alternate DNF module stream, so you can switch streams using the distribution's own tooling.
How DNF Module Streams Work on Rocky Linux 9
A DNF module groups related packages, such as a database server and its client libraries, into named streams. Each stream tracks a specific upstream version. Enabling a stream tells DNF which version to install by default. Profiles within a module, such as server or client, install predefined package sets.
Rocky Linux 9 makes PostgreSQL 13 the default stream. PostgreSQL 15 is available as a non-default stream in the base repository. You cannot install packages from two PostgreSQL streams at the same time, and you cannot enable a new stream while packages from the current stream remain installed. The module must be reset first, which removes the stream association without removing packages by itself.
Worked Example: Switch to PostgreSQL 15
Run these commands on a Rocky Linux 9 host. You need root or sudo privileges.
# 1. List available PostgreSQL streams
$ dnf module list postgresql
# 2. Remove any installed PostgreSQL packages from the default stream
# Skip this on a fresh system. On a system with existing data,
# dump databases first; see the limitation below.
$ sudo dnf remove -y postgresql* psql*
# 3. Reset the module so DNF forgets the enabled stream
$ sudo dnf module reset -y postgresql
# 4. Enable the PostgreSQL 15 stream
$ sudo dnf module enable -y postgresql:15
# 5. Install the server profile
$ sudo dnf install -y @postgresql:15/server
# 6. Initialize the database cluster if this is a fresh install
$ sudo su - postgres -c '/usr/pgsql-15/bin/initdb -D /var/lib/pgsql/15/data'
# 7. Start and enable the service
$ sudo systemctl enable --now postgresql-15
# 8. Verify the running version
$ /usr/pgsql-15/bin/postgres --version
$ sudo -u postgres /usr/pgsql-15/bin/psql -c 'SELECT version();'
Expected checks: dnf module list postgresql should show postgresql:15 with an [e] or [x] marker after enabling. postgres --version should print postgres (PostgreSQL) 15.x. The psql query should return a version string beginning with PostgreSQL 15.
Risk: If an existing PostgreSQL 13 data directory is present, removing packages and initializing a new cluster will make that data inaccessible. Configuration files under /var/lib/pgsql/13/data are not removed by package removal, but the new 15 cluster will not read them. You must perform a logical dump and restore.
Limitation: Stream Switching Requires a Database Dump and Restore
DNF module streams are not an in-place upgrade path. Enabling PostgreSQL 15 after PostgreSQL 13 has initialized a data directory does not migrate tables or users automatically. You must dump from the old version, remove the old packages, initialize the new cluster, and restore the dump. Plan downtime accordingly.
Also, module state is global. Enabling postgresql:15 affects every package that depends on the postgresql module, so check dependent applications before changing the stream on a shared host.
Verify the Result
After installation, confirm the active stream and binary version:
$ dnf module list postgresql
$ rpm -q postgresql-server
$ /usr/pgsql-15/bin/postgres --version
If rpm -q postgresql-server returns a 15.x release and the server starts on port 5432, the stream switch succeeded.
Next Steps
- Test the stream switch on a non-production Rocky Linux 9 instance.
- Dump existing databases before removing the default PostgreSQL packages.
- Enable
postgresql:15, install the server profile, and restore the dump. - Update application connection strings, firewall rules, and SELinux contexts if the port or authentication method changed.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.