Enable PostgreSQL 13 on CentOS 8/Stream 9 Using DNF Modules
Learn how to activate the PostgreSQL 13 module stream on CentOS 8 or Stream 9, install the server, initialize the database, and verify the setup. Follow this concise task guide with commands, checks, and recovery options.
07 Jul 2025, 00:24 UTC

Desired Outcome
Activate the PostgreSQL 13 module stream on a CentOS 8 or CentOS Stream 9 system, install the corresponding server and client packages, initialize a new database cluster, start the service, and confirm that the running instance is indeed PostgreSQL 13.
Prerequisites
- Root or
sudoaccess on the target machine. - Internet connectivity to reach CentOS repositories.
- For CentOS 8, ensure the
AppStreamrepository is enabled; for CentOS Stream 9 the same applies. - If a PostgreSQL cluster already exists, back it up before proceeding, as re‑initialization will erase data.
Procedure
Verify Current Module Status
Run the following to see which PostgreSQL streams are available and which are enabled:
sudo dnf module list postgresqlLook for a line similar to
postgresql:13 stream enabledafter enabling.Enable the PostgreSQL 13 Stream
Activate the desired stream. This command will resolve dependencies and remove conflicting packages from other streams.
sudo dnf module enable postgresql:13Check the list again to confirm:
sudo dnf module status postgresqlInstall the Server Package
With the stream enabled, install the server (and client libraries) that match the stream:
sudo dnf install -y postgresql-serverAfter installation,
dnf list installed | grep postgresqlshould showpostgresql-13.xandpostgresql-libs-13.x.Initialize the Database Cluster
PostgreSQL requires an initial cluster before it can run. The
postgresql-setupscript handles this in CentOS.sudo postgresql-setup --initdbOn CentOS 9 the syntax is the same. This creates
/var/lib/pgsql/13/dataand sets ownership to thepostgresuser.Start and Enable the Service
Enable the service to start on boot and start it immediately:
sudo systemctl enable --now postgresqlVerify the service status:
sudo systemctl status postgresqlConfirm PostgreSQL Version
Switch to the
postgresuser and query the server version:sudo -i -u postgres psql --versionAlternatively, connect to the server and run
SELECT version();:sudo -i -u postgres psql -c "SELECT version();"
Verification Checklist
| Check | Command | Expected Result |
|---|---|---|
| Module Stream | sudo dnf module status postgresql | 13 stream enabled |
| Installed Packages | sudo dnf list installed | grep postgresql | postgresql-13.x listed |
| Service Active | sudo systemctl is-active postgresql | active (running) |
| Server Version | sudo -i -u postgres psql --version | psql 13.x |
| Cluster Data Directory | ls -ld /var/lib/pgsql/13/data | exists, owned by postgres |
Recovery / Rollback
- If the module enabled step removed packages you need, you can disable the stream and enable a different one:
sudo dnf module disable postgresql:13
sudo dnf module enable postgresql:12
postgresql-setup --initdb again.Limitations & Notes
- CentOS 8 reached end‑of‑life in 2021. For production workloads, use CentOS Stream 9 or another supported RHEL‑derived distribution.
- Enabling a module stream can downgrade or remove packages from other streams. Always review the list of affected packages with
dnf module statusbefore proceeding. - The
postgresql-setup --initdbcommand will overwrite an existing cluster. Back up/var/lib/pgsql/13/dataif it contains important data. - Firewall rules and SELinux contexts are not modified by this guide. Ensure
firewalldallows the PostgreSQL port (default 5432) and that SELinux is permissive for PostgreSQL if using enforcing mode.
Practical Check
After completing the steps, a quick test is to create a temporary table:
sudo -i -u postgres psql -c "CREATE TABLE test(id INT);"
If the command succeeds, the database is fully operational. Drop the table afterward:
sudo -i -u postgres psql -c "DROP TABLE test;"
Summary
By enabling the PostgreSQL 13 module stream, installing the server package, initializing the cluster, and verifying the service, you have a clean, version‑specific PostgreSQL installation on CentOS 8 or Stream 9. The module system keeps your system tidy, automatically handling dependencies and avoiding conflicts with other PostgreSQL streams.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.