Skip to content
Download all

4.1 Add the
PGDG repository

4.2 Install
the packages

4.3 Create the
data directory
(initdb)

4.4 Start and enable
the service

Four steps, always in this order. Each step needs the one before it.

Definition: A repository is an online store of packages that dnf can download from. Adding the PGDG repository tells dnf where to find PostgreSQL's own packages.

On suta-linux-lab-1, as student:

suta-linux-lab-1 - as student
# Install the small package that adds the PGDG repository to dnf
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  • dnf install installs a package.
  • -y answers "yes" to the confirmation question.
  • The long address is the repository package for Enterprise Linux 9 (EL-9) on 64-bit Intel and AMD (x86_64).

Expected output (yours will differ):

...
Installed:
pgdg-redhat-repo-42.0-71.rhel9PGDG.noarch
Complete!

Still as student on suta-linux-lab-1:

suta-linux-lab-1 - as student (CentOS Stream only)
# Replace "major.minor" with just "major" in the PGDG repository file
sudo sed -i 's/\$releasever_major\.\$releasever_minor/$releasever_major/' /etc/yum.repos.d/pgdg-redhat-all.repo
  • sed (stream editor) changes text in a file from the command line, without opening it in vi.
  • sed -i edits the file in place.
  • The pattern swaps $releasever_major.$releasever_minor for $releasever_major, so the address becomes rhel-9-x86_64.

Next, stop dnf from using the operating system's own PostgreSQL packages, so the two sources cannot mix:

suta-linux-lab-1 - as student
# Turn off the OS AppStream PostgreSQL module
sudo dnf -qy module disable postgresql
  • module disable postgresql hides the OS vendor's PostgreSQL packages.
  • -q means quiet, -y means yes.

The first time, dnf imports the PGDG signing key. Expected output (yours will differ):

Importing GPG key 0x08B40D20:
Userid : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
From : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
...

Still as student on suta-linux-lab-1:

suta-linux-lab-1 - as student
# Install the PostgreSQL 18 server and the extra modules (contrib)
sudo dnf install -y postgresql18-server postgresql18-contrib
Package What it contains
postgresql18-server The server program postgres and the setup tools
postgresql18 The client tools, such as psql (installed automatically)
postgresql18-libs Shared libraries every PostgreSQL program needs (installed automatically)
postgresql18-contrib Extra extensions you will use later, such as pg_stat_statements

Expected output (yours will differ):

postgresql18-contrib x86_64 18.7-1PGDG.rhel9.9 pgdg18 764 k
postgresql18-server x86_64 18.7-1PGDG.rhel9.9 pgdg18 7.3 M
postgresql18 x86_64 18.7-1PGDG.rhel9.9 pgdg18 2.0 M
postgresql18-libs x86_64 18.7-1PGDG.rhel9.9 pgdg18 313 k
...
Complete!

Definition: A database cluster is the set of databases that one PostgreSQL server manages, stored in one folder called the data directory (or PGDATA). initdb creates that folder and fills it with everything the server needs to start.

initdb

Empty folder
/var/lib/pgsql/18/data

Ready data directory
databases: postgres, template0, template1
config files
WAL folder

On the left is an empty folder. initdb writes the three starting databases, the configuration files and the write-ahead log folder into it. The server cannot start until this has happened.

The PGDG package includes a setup script that runs initdb for you with safe settings. Still as student on suta-linux-lab-1:

suta-linux-lab-1 - as student
# Create the data directory with the PGDG setup script
sudo /usr/pgsql-18/bin/postgresql-18-setup initdb
  • /usr/pgsql-18/bin/ is where PGDG puts the PostgreSQL 18 programs.
  • initdb is the action we ask the script to perform.

Expected output:

Initializing database ... OK

The script also chooses safe login rules: peer for local connections and scram-sha-256 passwords for network connections. These rules live in a file called pg_hba.conf. You will open it in 6.2 and change it in 7.2. In PostgreSQL 18, initdb also turns on data checksums by default, so the server can detect damaged data pages.

4.4 Start the service and enable it at boot

Section titled “4.4 Start the service and enable it at boot”

Definition: A service is a program that systemd runs in the background. Starting it runs it now. Enabling it makes it start again every time the server boots.

On Windows this is the Services window, with "Start" and "Startup type: Automatic".

Still as student on suta-linux-lab-1:

suta-linux-lab-1 - as student
# Enable the service at boot and start it now, in one command
sudo systemctl enable --now postgresql-18
  • systemctl controls services.
  • enable adds the service to the boot sequence.
  • --now also starts it immediately.
  • postgresql-18 is the PGDG service name. The version is part of the name.

Expected output:

Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-18.service → /usr/lib/systemd/system/postgresql-18.service.

Check that it is running:

suta-linux-lab-1 - as student
# Show the service state without paging
systemctl status postgresql-18 --no-pager
  • --no-pager prints everything at once instead of opening a scrolling viewer.

Expected output (yours will differ):

● postgresql-18.service - PostgreSQL 18 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-18.service; enabled; preset: disabled)
Active: active (running) since Wed 2026-12-02 23:03:42 UTC; 400ms ago
Docs: https://www.postgresql.org/docs/18/static/
Main PID: 930 (postgres)
...

Look for enabled (starts at boot) and active (running) (running now).

Was this page helpful?

Thanks. Glad it helped.

Thanks for telling us. Email the instructor what was missing, or ask in class.