Skip to content
Runbook

Install PostgreSQL on Arch

Open source SQL relational database, robust and standards-compliant.

Databasesqlrdbmsrelationalaciddatabase

Installation

Server (pacman) · pacman
sudo pacman -S postgresql

The package includes the server, the psql client, and the utilities.

Initialize the cluster · pacman
sudo -iu postgres initdb -D /var/lib/postgres/data

MANDATORY step, run as the postgres user.

Verify the installation

Verify
psql --version

Service

Start
sudo systemctl start postgresql
Stop
sudo systemctl stop postgresql
Status
sudo systemctl status postgresql
Restart
sudo systemctl restart postgresql
On boot
sudo systemctl enable postgresql

Important files

TypePathDescription
data/var/lib/postgres/dataCluster data directory.
config/var/lib/postgres/data/postgresql.confServer configuration, located in the data directory.
config/var/lib/postgres/data/pg_hba.confClient authentication rules, located in the data directory.

Default ports

5432

Command-line tools

  • psqlInteractive SQL client.
  • pg_dumpLogical backup of a database.
  • pg_restoreRestore from a custom-format backup.
  • createdbQuickly create a database.
  • initdbInitialize a new cluster.

Uninstall

Uninstall
sudo systemctl stop postgresql
sudo pacman -Rns postgresql

The /var/lib/postgres/data directory remains; delete it manually to wipe everything.

Good to know

  • Arch only provides the latest major version; major upgrades require a data migration (pg_upgrade or dump/restore) — verify against the version.
  • Initialization must be done as the postgres user so that the data directory permissions are correct.

Installing on Arch Linux

The postgresql package from the official repositories (Extra) contains the server, the psql client, and the utilities. The installation creates the postgres system user, but does not create the cluster.

Initialize the cluster as the postgres user

You must initialize the data directory manually, and necessarily as the postgres user to guarantee the correct permissions:

sudo -iu postgres initdb -D /var/lib/postgres/data

Once the cluster is created, enable and start the systemd service. The first connection is made with sudo -iu postgres psql.

Major upgrades

Arch follows the "rolling release" model and only offers the latest major version of PostgreSQL. When jumping a major version (for example 16 to 17), the format of the data directory changes: you will have to migrate with pg_upgrade or via a pg_dump / restore cycle. Always back up your data before such an upgrade — verify against the version.