4. Install on Linux
Four steps, always in this order. Each step needs the one before it.
4.1 Add the PGDG repository
Section titled “4.1 Add the PGDG repository”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:
# Install the small package that adds the PGDG repository to dnfsudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpmdnf installinstalls a package.-yanswers "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:
# Replace "major.minor" with just "major" in the PGDG repository filesudo sed -i 's/\$releasever_major\.\$releasever_minor/$releasever_major/' /etc/yum.repos.d/pgdg-redhat-all.reposed(stream editor) changes text in a file from the command line, without opening it invi.sed -iedits the file in place.- The pattern swaps
$releasever_major.$releasever_minorfor$releasever_major, so the address becomesrhel-9-x86_64.
Next, stop dnf from using the operating system's own PostgreSQL packages, so the two sources
cannot mix:
# Turn off the OS AppStream PostgreSQL modulesudo dnf -qy module disable postgresqlmodule disable postgresqlhides the OS vendor's PostgreSQL packages.-qmeans quiet,-ymeans 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...4.2 Install the packages
Section titled “4.2 Install the packages”Still as student on suta-linux-lab-1:
# 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!4.3 Create the data directory (initdb)
Section titled “4.3 Create the data directory (initdb)”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.
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:
# Create the data directory with the PGDG setup scriptsudo /usr/pgsql-18/bin/postgresql-18-setup initdb/usr/pgsql-18/bin/is where PGDG puts the PostgreSQL 18 programs.initdbis the action we ask the script to perform.
Expected output:
Initializing database ... OKThe 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:
# Enable the service at boot and start it now, in one commandsudo systemctl enable --now postgresql-18systemctlcontrols services.enableadds the service to the boot sequence.--nowalso starts it immediately.postgresql-18is 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:
# Show the service state without pagingsystemctl status postgresql-18 --no-pager--no-pagerprints 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.