Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Installation, Setup and Configuring  ›  Lesson

Installing with a Package Manager

Package Managers 12 minInstall a deliberately chosen major version from the PostgreSQL project's repository and learn where your platform puts the data and config.

Installing with a Package Manager

Pedal is moving its database to a new Ubuntu server. The quickest command, apt install postgresql, installs whatever major version that Ubuntu release happened to ship, which may be two versions behind. A DBA chooses the version on purpose and knows where every file lands.

The rule

Choose the major version, use the project's repository, then learn the layout.

Choose the major version. PostgreSQL releases one major version a year (16, 17, 18…) and supports each for five years. Minor releases (17.5 → 17.6) are bug and security fixes, safe to apply with a normal package upgrade. Major versions change the on-disk format and need a real upgrade, so pick one deliberately and pin it.

Use the project's repository. The PostgreSQL Global Development Group (PGDG) publishes packages for every supported version:

# Debian / Ubuntu
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install -y postgresql-17

# Rocky / RHEL 9 (after adding the PGDG repo package)
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql17-server
sudo /usr/pgsql-17/bin/postgresql-17-setup initdb
sudo systemctl enable --now postgresql-17

# macOS
brew install postgresql@17
brew services start postgresql@17

Learn the layout. Each family puts things in different places:

Debian / Ubuntu RHEL family
Data directory /var/lib/postgresql/17/main /var/lib/pgsql/17/data
Config files /etc/postgresql/17/main/ inside the data directory
Service name postgresql@17-main postgresql-17
First cluster created and started for you you run initdb via the setup script

Both create an operating-system user called postgres that owns the files, and a database superuser role with the same name.

If you forget a path, the server will tell you:

SHOW data_directory;
SHOW config_file;

The shortcut

Before typing any install command, answer three questions: which major version, from which repository, and where will data and config live? Writing the three answers down is your install plan.

Planning Pedal's new serverStep 1 of 4
  1. Which major version?

    The newest release that the app's drivers and extensions support: 17.

The trap is editing a config file that the server is not reading. On Debian and Ubuntu, postgresql.conf in the data directory does not exist; the real one is under /etc. SHOW config_file; settles the question.

Drills

Answer fast — trust the rule.

quick drill

Moving from 17.5 to 17.6 is a…

quick drill

On Ubuntu with PGDG packages, where is postgresql.conf for version 17?

quick drill

On Rocky Linux, after installing postgresql17-server, why does systemctl start postgresql-17 fail at first?

quick drill

Which query tells you, for certain, where the running server's data lives?

Remember

  • Choose the major version, use the project's repository, then learn the layout.
  • Minor updates are routine; major upgrades change the data format.
  • When unsure, ask the server: SHOW data_directory; and SHOW config_file;.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWrite the install plan

Write a short install plan for PostgreSQL on a new Ubuntu server for Pedal: which version, from where, where data and configuration will live, and how you will verify it. Explain why you would not just run apt install postgresql.