AlmaLinux 9: choosing a PostgreSQL version and initialising it
Test scope
Section titled “Test scope”In an AlmaLinux 9.8 privileged container: dnf module list postgresql, --downloadonly version comparisons, initdb, pg_ctl, psql and pg_hba.conf. Log: plans/content-expansion/evidence/logs/alma-postgresql-install.log.
Initialisation was executed on 13.23; 16.x follows the same flow but was not run separately. The postgresql-setup / systemctl path depends on systemd and was not verified in the container.
Two sources: non-modular 13 and module streams
Section titled “Two sources: non-modular 13 and module streams”dnf module list postgresqldnf -y install --downloadonly --destdir=/tmp/a postgresql-serverls /tmp/a | grep '^postgresql-server'postgresql 15 client, server [d]postgresql 16 client, server [d]postgresql 18 client, server [d]
postgresql-server-13.23-6.el9_8.x86_64.rpmThe module list shows 15/16/18, yet a plain install resolves 13.23: appstream also carries a non-modular 13, which dnf uses while no stream is enabled. That is EL9 packaging, not a bug.
Choose the version explicitly
Section titled “Choose the version explicitly”sudo dnf module enable postgresql:16sudo dnf -y install --downloadonly --destdir=/tmp/b postgresql-serverls /tmp/b | grep '^postgresql-server'postgresql-server-16.15-1.module+el9.8.0+40320+f6f9ed3c.x86_64.rpmOnly the module+el9.8.0 build comes from the stream. Enable, install, then confirm with rpm -q — do not skip any of the three.
Initialise: initdb in a container
Section titled “Initialise: initdb in a container”sudo mkdir -p /var/lib/pgsql/data /var/run/postgresqlsudo chown -R postgres:postgres /var/lib/pgsql /var/run/postgresqlsudo -u postgres /usr/bin/initdb -D /var/lib/pgsql/data \ --auth-local=trust --auth-host=scram-sha-256cat /var/lib/pgsql/data/PG_VERSIONsyncing data to disk ... ok13PG_VERSION records the major version; it is a more direct check than reading package names.
Start, connect and authenticate
Section titled “Start, connect and authenticate”sudo -u postgres /usr/bin/pg_ctl -D /var/lib/pgsql/data \ -l /var/lib/pgsql/data/startup.log -o '-k /var/run/postgresql' startsudo -u postgres psql -h /var/run/postgresql -tAc 'select version();'grep -vE '^#|^$' /var/lib/pgsql/data/pg_hba.confPostgreSQL 13.23 on x86_64-redhat-linux-gnu, ...local all all trusthost all all 127.0.0.1/32 scram-sha-256host all all ::1/128 scram-sha-256The standard path on a real host
Section titled “The standard path on a real host”sudo dnf module enable postgresql:16sudo dnf -y install postgresql-serversudo postgresql-setup --initdbsudo systemctl enable --now postgresqlpsql --versionpostgresql-setup initialises the cluster and registers the systemd unit; in a container it fails with System has not been booted with systemd, hence initdb there.
Common traps
Section titled “Common traps”- Skipping module enable: you get 13 while the application assumes 16;
- No
/var/run/postgresql: local socket connections fail; - Mixing module streams with PGDG: two sources for one major overwrite each other during upgrades.
Practice: from version choice to a working connection
Section titled “Practice: from version choice to a working connection”dnf module list postgresqlsudo dnf module enable postgresql:16sudo dnf -y install postgresql-serverrpm -q postgresql-server | grep modulesudo postgresql-setup --initdbsudo systemctl enable --now postgresqlsudo -u postgres psql -tAc 'select version();'Checks:
rpm -qoutput containsmodulesystemctl is-active postgresqlis activeselect version()reports 16.xcat PG_VERSIONis 16
常见问题
Why install 13 when the module list shows 15/16/18?
AppStream also ships a non-modular postgresql 13; without an enabled stream dnf resolves that package. Enable postgresql:16 first to get 16.
How do I confirm the version I wanted?
Three checks: `rpm -q postgresql-server` for `module` in the release, `cat /var/lib/pgsql/data/PG_VERSION` for the initialised major, and `psql -c "select version();"` for the running version.
Can PostgreSQL run in a container?
Yes, with initdb and pg_ctl; production should use systemd units or an orchestrator to own restarts and boot startup.
Next steps
Section titled “Next steps”- Container services: Quadlet services
- Post-install checks: 7 checks after install
- Log rotation: logrotate in practice