Skip to content
Search Fedora

    Browse this documentation

    Installing PostgreSQL on Fedora: choosing between 16, 17, 18 and 19beta

    Fedora packages PostgreSQL in an unusual way: four major versions sit in the repo at once, but you can install only one.

    Four PostgreSQL versions made mutually exclusive by postgresql-server-any

    Terminal window
    dnf list --available "postgresql1*-server.x86_64" 2>/dev/null | grep x86_64
    postgresql16-server.x86_64 16.14-5.fc45 fedora
    postgresql17-server.x86_64 17.9-10.fc45 fedora
    postgresql19-server.x86_64 19beta1-6.fc45 fedora

    Plus the unversioned name, which tracks the newest stable:

    Terminal window
    dnf list --available postgresql-server.x86_64
    postgresql-server.x86_64 18.3-12.fc45 fedora
    You wantInstallVersion
    PG 16postgresql16-server16.14
    PG 17postgresql17-server17.9
    PG 18 (default)postgresql-server18.3
    PG 19 (beta)postgresql19-server19beta1
    Terminal window
    sudo dnf install postgresql-server

    Modest size: 7.9 MiB download, 32.9 MiB installed.

    Confirm the binaries:

    Terminal window
    postgres --version
    psql --version
    postgres (PostgreSQL) 18.3
    psql (PostgreSQL) 18.3

    initdb first — the package does not do it

    Section titled “initdb first — the package does not do it”

    Fedora’s package does not initialize the data directory, so starting the service immediately fails. Initialize:

    Terminal window
    sudo postgresql-setup --initdb
    * Initializing database in '/var/lib/pgsql/data'
    * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

    The data directory is /var/lib/pgsql/data.

    Then start:

    Terminal window
    sudo systemctl enable --now postgresql
    systemctl is-active postgresql
    active

    Two units are present:

    postgresql.service disabled disabled
    [email protected] disabled disabled

    [email protected] is a template unit for running multiple instances on one host — the supported route for multi-instance needs (see below).

    Terminal window
    sudo -u postgres psql -c "select version();"
    PostgreSQL 18.3 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 16.2.1 20260819
    (Red Hat 16.2.1-2), 64-bit
    (1 row)

    Note the -u postgres: only the postgres system user can connect by default, because auth is peer-based.

    Terminal window
    ss -lntp | grep 5432
    LISTEN 0 200 127.0.0.1:5432 0.0.0.0:*
    LISTEN 0 200 [::1]:5432 [::]:*

    As with Valkey, the database is not exposed by default.

    Terminal window
    sudo grep -vE "^(#|$)" /var/lib/pgsql/data/pg_hba.conf
    local all all peer
    host all all 127.0.0.1/32 ident
    host all all ::1/128 ident
    local replication all peer
    • peer — on a local socket, the OS username must match the database username
    • ident — TCP connections also require an identity check

    So psql -U postgres fails as a normal user; use sudo -u postgres. To allow password login, switch the method to scram-sha-256 and set a password.

    Since the four repo packages are mutually exclusive, keeping 16 and 18 on one host takes one of three routes:

    ApproachHowTrade-off
    multi-instance (recommended)several instances of one version via [email protected], different ports and data dirssame version only
    PGDG repositoryadd PostgreSQL’s pgdg repo and install postgresql-16-server plus postgresql-18-serverextra repo
    containersone Podman container per versionstrongest isolation, more ops work

    The key to multi-instance is the template unit. The instance name maps to a data directory:

    Terminal window
    sudo postgresql-setup --initdb --unit postgresql@16-main \
    --port 5433 --datadir /var/lib/pgsql/16/data
    sudo systemctl enable --now postgresql@16-main

    Now 18 listens on 5432 and 16 on 5433, independent of each other.

    Terminal window
    sudo -u postgres psql # interactive psql
    sudo -u postgres createuser --interactive
    sudo -u postgres createdb mydb
    sudo -u postgres psql -c "\l" # list databases
    sudo -u postgres psql -c "\du" # list roles

    \q exits.

    SymptomCause
    service will not startpostgresql-setup --initdb was never run
    psql: FATAL: Peer authentication faileda normal user ran psql -U postgres; use sudo -u postgres
    pg_hba.conf edit has no effectforgot systemctl reload postgresql
    remote 5432 failsdefault bind is 127.0.0.1; change listen_addresses
    installing 16 and 18 together errorsthey conflict; use multi-instance or PGDG
    wrong data directory ownershipmust be postgres:postgres; restart after fixing