Skip to content
Search AlmaLinux

    Browse this documentation

    AlmaLinux 9: choosing a PostgreSQL version and initialising it

    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”
    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 16 client, server [d]
    postgresql 18 client, server [d]
    postgresql-server-13.23-6.el9_8.x86_64.rpm

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

    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

    Only the module+el9.8.0 build comes from the stream. Enable, install, then confirm with rpm -q — do not skip any of the three.

    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
    cat /var/lib/pgsql/data/PG_VERSION
    syncing data to disk ... ok
    13

    PG_VERSION records the major version; it is a more direct check than reading package names.

    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();'
    grep -vE '^#|^$' /var/lib/pgsql/data/pg_hba.conf
    PostgreSQL 13.23 on x86_64-redhat-linux-gnu, ...
    local all all trust
    host all all 127.0.0.1/32 scram-sha-256
    host all all ::1/128 scram-sha-256
    Terminal window
    sudo dnf module enable postgresql:16
    sudo dnf -y install postgresql-server
    sudo postgresql-setup --initdb
    sudo systemctl enable --now postgresql
    psql --version

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

    • 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”
    Terminal window
    dnf module list postgresql
    sudo dnf module enable postgresql:16
    sudo dnf -y install postgresql-server
    rpm -q postgresql-server | grep module
    sudo postgresql-setup --initdb
    sudo systemctl enable --now postgresql
    sudo -u postgres psql -tAc 'select version();'

    Checks:

    1. rpm -q output contains module
    2. systemctl is-active postgresql is active
    3. select version() reports 16.x
    4. cat PG_VERSION is 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.