Menu

Install PostgreSQL on macOS with Homebrew

Install PostgreSQL on macOS with Homebrew, start its service, create a database owned by your app role, and connect with psql.

Posted on By Updated on
On this page

This guide installs PostgreSQL with Homebrew, starts the server as a macOS service, and creates a database that your application role owns.

Check Homebrew support

Homebrew’s Tier 1 macOS setup currently targets Apple Silicon Macs running macOS Sequoia (15) or later. Intel Macs and older macOS versions may work with reduced support; check Homebrew’s current installation requirements before installing.

Install Homebrew by following the instructions at brew.sh. Bottled formulae on Apple Silicon do not always require Xcode Command Line Tools; Homebrew requires them when it must build a formula from source.

Install PostgreSQL

Update Homebrew’s formula metadata, then install its PostgreSQL formula:

brew update
brew install postgresql

Homebrew’s unversioned postgresql formula currently aliases postgresql@18. If you need a specific major version, install its versioned formula and follow the service command shown on the Homebrew PostgreSQL formula page.

Start the versioned service and check its status:

brew services start postgresql@18
brew services list
pg_isready

brew services start starts PostgreSQL now and registers it to start at login. If Homebrew installed a different major-version formula, use that formula’s name in the service command. To stop it later, run brew services stop postgresql@18.

Create an application role and database

Homebrew initializes a local cluster when it installs the formula. The initial PostgreSQL superuser normally has the same name as the operating-system account that ran initdb; see the initdb documentation. Connect to the default postgres database as that role:

psql -d postgres

Create a login role and make it the owner of an application database:

CREATE ROLE app_user WITH LOGIN PASSWORD 'change_me';
CREATE DATABASE app_db OWNER app_user;

Creating the database with OWNER app_user lets the application role own its database. This is important with PostgreSQL 15 and later, where the default public schema privileges changed; the database owner receives ownership privileges on that database’s public schema. See the PostgreSQL 15 release notes.

Exit the initial psql session, then connect as the application role:

\q
psql -h localhost -U app_user -d app_db -W

The -W option prompts for the password. Verify the connection and create a table:

SELECT current_user, current_database();

CREATE TABLE example (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100),
  age INT
);

PostgreSQL’s CREATE DATABASE reference documents the OWNER option.

Manage the service

Use the same versioned formula name to manage the service:

brew services stop postgresql@18
brew services restart postgresql@18

If you installed a different major version, substitute its formula name. Homebrew’s formula page lists the current version and service command.

Next steps

Use the PostgreSQL tutorials and PostgreSQL reference to continue learning.