Skip to content
Search Rocky Linux

    Browse this documentation

    Rocky 9 PostgreSQL: pick the stream first, then initialise

    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).

    Terminal window
    dnf module list postgresql
    dnf -y install --downloadonly --destdir=/tmp/a postgresql-server
    ls /tmp/a | grep '^postgresql-server'
    postgresql 15 client, server [d] PostgreSQL server and client module
    postgresql 16 client, server [d] PostgreSQL server and client module
    postgresql 18 client, server [d] PostgreSQL server and client module
    postgresql-server-13.23-6.el9_8.x86_64.rpm

    The 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”
    Terminal window
    sudo dnf module enable postgresql:16
    sudo dnf -y install --downloadonly --destdir=/tmp/b postgresql-server
    ls /tmp/b | grep '^postgresql-server'
    postgresql-server-16.15-1.module+el9.8.0+40320+f6f9ed3c.x86_64.rpm

    The module+el9.8.0 marker shows the package came from the stream. Confirm the version before installing, not after.

    Terminal window
    sudo mkdir -p /var/lib/pgsql/data /var/run/postgresql
    sudo chown -R postgres:postgres /var/lib/pgsql /var/run/postgresql
    sudo -u postgres /usr/bin/initdb -D /var/lib/pgsql/data \
    --auth-local=trust --auth-host=scram-sha-256
    syncing data to disk ... ok
    Success. 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.

    Terminal window
    sudo -u postgres /usr/bin/pg_ctl -D /var/lib/pgsql/data \
    -l /var/lib/pgsql/data/startup.log -o '-k /var/run/postgresql' start
    sudo -u postgres psql -h /var/run/postgresql -tAc 'select version();'
    waiting for server to start.... done
    server started
    PostgreSQL 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.

    Terminal window
    grep -vE '^#|^$' /var/lib/pgsql/data/pg_hba.conf
    local all all trust
    host all all 127.0.0.1/32 scram-sha-256
    host all all ::1/128 scram-sha-256

    local is the Unix socket, host is TCP. Changes need pg_ctl reload or a restart.

    Terminal window
    sudo postgresql-setup --initdb
    sudo systemctl enable --now postgresql
    sudo -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).

    • A plain dnf install postgresql-server gives 13, not 15/16;
    • Missing socket directory: without /var/run/postgresql, psql cannot connect;
    • pg_hba edited without reload: authentication rules stay unchanged.

    Practice: confirm the version before installing

    Section titled “Practice: confirm the version before installing”
    Terminal window
    dnf module list postgresql
    sudo dnf module enable postgresql:16
    sudo dnf -y install postgresql-server
    rpm -q postgresql-server
    sudo postgresql-setup --initdb
    sudo systemctl enable --now postgresql
    sudo -u postgres psql -c 'select version();'

    Checks:

    1. rpm -q postgresql-server shows 16.x (with module in the release)
    2. systemctl is-active postgresql is active
    3. psql -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.