Switch PostgreSQL Streams on Rocky Linux 9 with DNF Modules
Learn how to install PostgreSQL 13 or 15 on Rocky Linux 9 using DNF module streams, switch between them, and validate the active version—all with a step‑by‑step guide and recovery tips.
22 Aug 2025, 01:02 UTC

Desired Outcome
Enable a Rocky Linux 9 administrator to install PostgreSQL 13 or 15 from the AppStream repository, switch between them, and verify the active version—all without reinstalling the OS.
Prerequisites
- Rocky Linux 9 system with a recent kernel (≥ 4.18) and fully updated packages.
- Root or
sudoaccess. - AppStream repository enabled (default on fresh installs).
- Backup of any pre‑existing PostgreSQL data (e.g.,
pg_dumpallor a filesystem snapshot). - SELinux in enforcing mode (default) – be prepared to adjust contexts if moving
$PGDATA.
Procedure
List Available PostgreSQL Streams
# dnf module list postgresqlLook for the
postgresqlmodule and note the stream numbers (e.g.,13,15). The current stream will have a[e]next to it.Enable the Desired Stream
# sudo dnf module enable postgresql:13Replace
13with the target version. The command removes any conflicting packages from other streams.Install PostgreSQL Server
# sudo dnf install -y postgresql-serverDNF pulls the packages that belong to the enabled stream.
Initialize the Database Cluster
# sudo postgresql-setup --initdbThis creates
/var/lib/pgsql/data(or$PGDATA) and sets up system tables.Start and Enable the Service
# sudo systemctl enable --now postgresqlService name is
postgresqlregardless of stream; the binary path is chosen by the module.Verify the Active Version
# psql --version # psql -U postgres -c "SELECT version();"The output should include the stream’s major version (e.g.,
PostgreSQL 13).
Switching Streams
Disable Current Stream
# sudo dnf module disable postgresqlEnable New Stream
# sudo dnf module enable postgresql:15Re‑install and Re‑initialize
# sudo dnf install -y postgresql-server # sudo postgresql-setup --initdbNote: This creates a fresh cluster; migrate data from the old cluster before dropping it.
Restart Service
# sudo systemctl restart postgresqlConfirm New Version
# psql -U postgres -c "SELECT version();"
Validation
- Run
dnf module list postgresqlagain; the[e]should now be on the new stream. - Check service status:
systemctl status postgresqlshould showActive: active (running)and the service description includes the version. - Query PostgreSQL:
SELECT version();must match the expected major release.
Recovery / Rollback
If the new stream causes problems, revert to the previous one following the same steps: disable the current stream, enable the former stream, reinstall, re‑initialize (or restore a backup), and restart the service. Ensure you have a backup before dropping any cluster.
Limitations & Notes
- Switching streams replaces the PostgreSQL binaries; it does not migrate existing databases automatically. Use
pg_dumpallor a file‑system snapshot before switching. - Data directories may need SELinux context adjustments if moved:
semanage fcontext -a -t postgresql_db_t '/new/pgdata(/.*)?'andrestorecon -Rv /new/pgdata. - Only supported streams available in AppStream can be enabled; custom or older versions require manual RPM builds.
Practical Check
After following the steps, a quick sanity test is to connect locally with psql -U postgres -c "SELECT current_setting('server_version');" and confirm the returned string matches the stream you enabled.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.