Rocky 9 PostgreSQL: pick the stream first, then initialise
Test scope
Section titled “Test scope”In a Rocky Linux 9.8 privileged container: dnf module list postgresql, --downloadonly comparisons of the resolved package, initdb, pg_ctl start, psql, and pg_hba.conf. Log: plans/content-expansion/evidence/logs/rocky-postgresql-install.log.
The initialisation flow was executed on 13.23; 16.x follows the same flow with different version numbers and was not run separately. The systemd path (postgresql-setup / systemctl) was not verified (no systemd in the container).
Bottom line: a plain install gives you 13
Section titled “Bottom line: a plain install gives you 13”dnf module list postgresqldnf -y install --downloadonly --destdir=/tmp/a postgresql-serverls /tmp/a | grep '^postgresql-server'postgresql 15 client, server [d] PostgreSQL server and client modulepostgresql 16 client, server [d] PostgreSQL server and client modulepostgresql 18 client, server [d] PostgreSQL server and client module
postgresql-server-13.23-6.el9_8.x86_64.rpmThe module list shows 15/16/18, but a plain install resolves to 13.23 — appstream also ships a non-modular 13, and dnf uses it while no module stream is enabled.
For a newer major: enable the stream first
Section titled “For a newer major: enable the stream first”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.rpmThe module+el9.8.0 marker shows the package came from the stream. Confirm the version before installing, not after.
Initialise the data directory
Section titled “Initialise the data directory”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-256syncing data to disk ... okSuccess. You can now start the database server using: /usr/bin/pg_ctl -D /var/lib/pgsql/data -l logfile start--auth-local=trust is for local testing only; production keeps scram-sha-256 and sets a password for the postgres user.
Start and connect
Section titled “Start and connect”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();'waiting for server to start.... doneserver startedPostgreSQL 13.23 on x86_64-redhat-linux-gnu, ...Without systemd in the container, start it with pg_ctl; -k sets the socket directory, otherwise the client cannot find the local socket.
What pg_hba looks like
Section titled “What pg_hba looks like”grep -vE '^#|^$' /var/lib/pgsql/data/pg_hba.conflocal all all trusthost all all 127.0.0.1/32 scram-sha-256host all all ::1/128 scram-sha-256local is the Unix socket, host is TCP. Changes need pg_ctl reload or a restart.
On a host with systemd
Section titled “On a host with systemd”sudo postgresql-setup --initdbsudo systemctl enable --now postgresqlsudo -u postgres psql -c 'select version();'On a real host these two commands are the standard path; they need systemd and fail in a container with System has not been booted with systemd (observed here).
Common traps
Section titled “Common traps”- A plain
dnf install postgresql-servergives 13, not 15/16; - Missing socket directory: without
/var/run/postgresql,psqlcannot connect; - pg_hba edited without reload: authentication rules stay unchanged.
Practice: confirm the version before installing
Section titled “Practice: confirm the version before installing”dnf module list postgresqlsudo dnf module enable postgresql:16sudo dnf -y install postgresql-serverrpm -q postgresql-serversudo postgresql-setup --initdbsudo systemctl enable --now postgresqlsudo -u postgres psql -c 'select version();'Checks:
rpm -q postgresql-servershows 16.x (withmodulein the release)systemctl is-active postgresqlis activepsql -c 'select version();'reports 16.x
常见问题
Why does dnf install 13 instead of the default stream 15?
AppStream provides both a non-modular postgresql 13 and the 15/16/18 module streams; with no stream enabled dnf resolves the non-modular package. Enable a stream first for 15/16/18.
Module streams or the PGDG repository?
Streams ship with the distribution and follow its lifecycle, good for stable majors; PGDG is for newer minors and extensions. Do not mix both for the same major.
postgresql-setup --initdb fails with a systemd error?
It depends on systemd; in containers or rescue environments initialise with initdb directly and start with pg_ctl.
Next steps
Section titled “Next steps”- Container services: Quadlet services
- Log rotation: logrotate in practice
- Post-install checks: 7 checks after install