Start using PostgreSQL
Install PostgreSQL 18 on macOS
Install the PostgreSQL 18 Homebrew formula without treating a major-version upgrade like an ordinary package update.
On macOS, install the PostgreSQL 18 formula with Homebrew:
brew install postgresql@18
brew services start postgresql@18
The first command installs the server and its client tools. The second registers PostgreSQL as a background service, so it starts now and again after every reboot. Homebrew also creates the initial data directory and a superuser role named after your macOS user, which is why you can connect right away without a password.
Use the official PostgreSQL downloads for Windows or Linux. The rest of the course works the same on every platform once the server runs.
Put the tools on your PATH
The versioned formula is keg-only, so Homebrew does not link psql into your default path. Add the formula’s bin directory to your shell path if Homebrew asks you to:
echo 'export PATH="/opt/homebrew/opt/postgresql@18/bin:$PATH"' >> ~/.zshrc
Open a new terminal, then verify both programs:
psql --version
pg_config --version
Both commands should report PostgreSQL 18. If you see psql: command not found, the path line is missing or the shell has not reloaded it yet.
Verify the server is running
Check the service state:
brew services list
Name Status User File
postgresql@18 started flavio ~/Library/LaunchAgents/[email protected]
started in green means the server is up. error means it failed to boot; look at the log file under /opt/homebrew/var/log/ before trying anything else.
Upgrades are not all equal
A minor update inside PostgreSQL 18, say 18.1 to 18.2, is an ordinary package update. It fixes bugs and security issues without touching your data format.
A future move from 18 to 19 is a database-cluster upgrade. The on-disk data layout can change between major versions, so the new server cannot just open the old files. Back up first and use pg_upgrade, dump and restore, or logical replication.
Do not uninstall the old server and hope its data follows the new package. That is the classic way people end up with a running PostgreSQL 19 and an invisible, orphaned PostgreSQL 18 data directory. The versioned formula name, postgresql@18, exists exactly so a casual brew upgrade cannot move you across a major version by accident.
Lesson completed