Skip to content
Runbook

Install PostgreSQL on macOS

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

Databasesqlrdbmsrelationalaciddatabase

Installation

Server (Homebrew) · Homebrew
brew install postgresql@17

The versioned formula avoids unexpected major upgrades.

Verify the installation

Verify
psql --version

Service

Start
brew services start postgresql@17
Stop
brew services stop postgresql@17
Status
brew services info postgresql@17
Restart
brew services restart postgresql@17

Important files

TypePathDescription
data/opt/homebrew/var/postgresql@17Cluster data directory (Apple Silicon). On Intel Mac: /usr/local/var/postgresql@17.
config/opt/homebrew/var/postgresql@17/postgresql.confServer configuration, located in the data directory.
config/opt/homebrew/var/postgresql@17/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 pg_dump backup.
  • createdbQuick creation of a database.
  • pg_ctlLow-level server control.

Uninstall

Uninstall
brew services stop postgresql@17
brew uninstall postgresql@17

The data directory is not removed: delete it manually if needed.

Good to know

  • Homebrew does not use systemd: service management goes through brew services.
  • Being a versioned formula, postgresql@17 is keg-only: its binaries are never linked into the global PATH; add /opt/homebrew/opt/postgresql@17/bin to your PATH.

Installation with Homebrew

Homebrew is the standard method on macOS. The postgresql@17 formula installs the server, the psql client, and the utilities, then runs initdb at install time (per the Homebrew caveats) to create the cluster in the data directory.

The default PostgreSQL user matches your macOS account (not postgres). You can therefore connect directly with psql postgres once the service is started.

Paths by architecture

The Homebrew prefix differs between chips: /opt/homebrew on Apple Silicon (M1/M2/M3…) and /usr/local on Intel Macs. The data and configuration paths shown above assume Apple Silicon; adjust the prefix on Intel.

Common pitfall: binaries outside the PATH

Because it is a versioned formula, postgresql@17 is always "keg-only": its binaries are never linked into the global PATH. You must therefore add the formula's bin directory to your PATH, for example in ~/.zshrc: export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH".