PostgreSQL, often affectionately called “Postgres,” is a powerful, open-source object-relational database system renowned for its robustness, extensibility, and strict adherence to SQL standards. For developers, data scientists, and system administrators working on macOS, having a local PostgreSQL instance is invaluable for development, testing, and managing datasets. This guide will walk you through the most common and recommended methods for installing PostgreSQL on your Mac, ensuring you can get started with this versatile database swiftly and efficiently.
Understanding PostgreSQL Installation Options on macOS
Before diving into the installation process, it’s beneficial to understand the primary ways PostgreSQL can be deployed on macOS. Each method offers distinct advantages, catering to different user needs and technical preferences.

Official Installer vs. Package Managers
The two most prevalent approaches involve using the official PostgreSQL installer provided by the PostgreSQL community or leveraging macOS package managers like Homebrew.
Official PostgreSQL Installer
The PostgreSQL Global Development Group (PGDG) offers dedicated installers for macOS. These installers are typically comprehensive, bundling the database server, command-line tools, and often a graphical administration tool like pgAdmin. This method is straightforward and provides a well-integrated experience, ensuring all components are set up harmoniously. It’s an excellent choice for users who prefer a self-contained installation and want direct control over the PostgreSQL version and its associated utilities.
Advantages:
- Self-contained: Includes all necessary components.
- Direct from source: Ensures compatibility and access to the latest stable releases.
- Graphical installer: Simplifies the initial setup for many users.
- Includes pgAdmin: Often bundled, offering a user-friendly GUI for database management.
Disadvantages:
- Manual updates: Updating PostgreSQL typically requires downloading and running a new installer.
- Dependency management: Less automated than package managers for other software.
Homebrew: The macOS Package Manager
Homebrew is a popular, free and open-source software package manager that simplifies the installation of software on Apple’s macOS operating system. For developers and command-line enthusiasts, Homebrew is an indispensable tool. Installing PostgreSQL via Homebrew is remarkably easy and integrates seamlessly with other development tools you might have installed using the same package manager.
Advantages:
- Ease of installation: A single command installs PostgreSQL and its dependencies.
- Simplified updates: Updates can be managed with simple
brew upgradecommands. - Dependency handling: Homebrew automatically manages dependencies required by PostgreSQL.
- Integration: Works well with other Homebrew-installed software.
Disadvantages:
- Command-line focused: Primarily managed through the terminal.
- May lag behind PGDG installers: Sometimes slightly behind the absolute latest official releases.
Docker: Containerized PostgreSQL
For those who work with multiple database versions, need isolated environments, or are already invested in containerization, Docker presents another powerful option. Installing PostgreSQL via Docker involves pulling a pre-built PostgreSQL image from Docker Hub and running it as a container. This method offers maximum flexibility and isolation but requires a basic understanding of Docker concepts.
Advantages:
- Isolation: Each PostgreSQL instance runs in its own container, preventing conflicts.
- Version flexibility: Easily run multiple PostgreSQL versions simultaneously.
- Reproducibility: Easily replicate the database environment across different machines.
- Clean uninstallation: Removing a container is straightforward.
Disadvantages:
- Learning curve: Requires familiarity with Docker.
- Resource overhead: Containers do consume system resources.
Installing PostgreSQL Using the Official Installer
This section details the steps for installing PostgreSQL on your Mac using the official installer from the PostgreSQL Global Development Group (PGDG). This method is generally recommended for users who prefer a graphical setup and a comprehensive package.
Step 1: Download the PostgreSQL Installer
- Navigate to the PostgreSQL Downloads Page: Open your web browser and go to the official PostgreSQL download page: https://www.postgresql.org/download/.
- Select macOS: Click on the “macOS” link under the operating system choices.
- Choose the Installer: You will be presented with several options. Look for the “Download the installer” link, which will direct you to the EnterpriseDB website (the official vendor for PostgreSQL installers).
- Select Version and OS: On the EnterpriseDB page, select the latest stable PostgreSQL version available for macOS. Ensure you choose the correct architecture for your Mac (e.g., Intel or Apple Silicon).
- Download the .dmg File: Click the download button. This will initiate the download of a
.dmgdisk image file.
Step 2: Run the Installer
- Open the .dmg File: Once the download is complete, locate the
.dmgfile (usually in your “Downloads” folder) and double-click it. This will mount the disk image. - Launch the Installer Package: Inside the mounted disk image, you will find a
.pkgfile (e.g.,postgresql-x.x.x-x-osx.dmg). Double-click this package file to start the installation wizard. - Follow the Installation Wizard:
- Introduction: Click “Continue.”
- License: Review the license agreement and click “Continue” and then “Agree.”
- Installation Type: Choose “Install for me only” or “Install on this computer.” “Install on this computer” is generally the default and recommended option for most users, requiring administrator privileges. Click “Continue.”
- Customization (Optional): You may have an option to customize components. For a standard installation, the defaults are usually sufficient.
- Password: This is a crucial step. You will be prompted to set a password for the PostgreSQL superuser, named
postgres. Choose a strong password and remember it. This password will be required to connect to your database as the superuser. - Installation Destination: Select where you want to install PostgreSQL. The default location is usually fine.
- Installation: Click “Install.” You may be prompted to enter your Mac’s administrator password to authorize the installation.
- Installation Complete: Once the installation is finished, you will receive a confirmation message. The installer often includes an option to launch Stack Builder, which can be used to install additional tools like pgAdmin. It is highly recommended to install pgAdmin if it’s not automatically included.
Step 3: Verify the Installation and Connect
- Launch pgAdmin (if installed): If pgAdmin was installed, you can find it in your “Applications” folder. Launch it.
- Connect to the Server:
- You should see a “PostgreSQL” server already listed. If not, right-click on “Servers” and select “Create” -> “Server…”
- Hostname:
localhost - Port:
5432(the default PostgreSQL port) - Username:
postgres(the default superuser) - Password: The password you set during the installation.
- Click “Save Password” and then “OK.”
- Connect via Terminal:
- Open the “Terminal” application (Applications -> Utilities -> Terminal).
- You need to ensure your
PATHenvironment variable includes the PostgreSQL binaries. The official installer usually handles this, or it might require manual configuration. A common approach is to add the PostgreSQLbindirectory to your PATH. - To connect to the default database (
postgres) as thepostgresuser, type:
bash
psql -U postgres
- You will be prompted for the
postgresuser’s password. Enter the password you set during installation. - If successful, you will see the
postgres=#prompt, indicating you are connected to the PostgreSQL server. - To exit
psql, typeqand press Enter.
Step 4: Starting and Stopping PostgreSQL
The official installer typically sets up PostgreSQL to start automatically on system boot. However, you can also manage the service manually.
- Using System Preferences (Older macOS): In older versions of macOS, you might find a PostgreSQL icon in your System Preferences pane that allows you to start/stop the server.
- Using
pg_ctl(Command Line):- Start: Navigate to your PostgreSQL installation directory’s
binfolder in the Terminal and run:
bash
pg_ctl -D /usr/local/var/postgres start
(Replace/usr/local/var/postgreswith your actual data directory path if different). - Stop:
bash
pg_ctl -D /usr/local/var/postgres stop
- Status:
bash
pg_ctl -D /usr/local/var/postgres status
- Start: Navigate to your PostgreSQL installation directory’s
Installing PostgreSQL Using Homebrew
Homebrew provides a streamlined and efficient way to install PostgreSQL on macOS. This method is highly recommended for developers who are comfortable with the command line.
Step 1: Install Homebrew (if you haven’t already)
If you don’t have Homebrew installed, open your Terminal and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions to complete the Homebrew installation.
Step 2: Update Homebrew and Install PostgreSQL
- Update Homebrew: Ensure your Homebrew package list is up-to-date by running:
bash
brew update
- Install PostgreSQL: Now, install PostgreSQL with a single command:
bash
brew install postgresql
Homebrew will download and install PostgreSQL and any necessary dependencies.
Step 3: Start the PostgreSQL Service
Homebrew installs PostgreSQL, but it doesn’t automatically start the service. You can start it manually or configure it to launch on startup.
-
Start Manually:
brew services start postgresqlThis command starts the PostgreSQL server and also sets it up to launch automatically every time you log in to your Mac.
-
Check Status:
bash
brew services list
This will show you the status of all services managed by Homebrew, including PostgreSQL.
Step 4: Verify the Installation and Connect
-
Connect via Terminal: Homebrew automatically configures the
PATHso you can access PostgreSQL commands easily.psql -U postgres- By default, Homebrew creates a PostgreSQL user named
postgreswith no password for local connections. You might be prompted for a password if you’ve previously configured one, or if you’re connecting from a remote location (which isn’t typical for a default local install). - If you encounter issues, you might need to manually create a user or set a password using
createuserandpsql.
- By default, Homebrew creates a PostgreSQL user named
-
Data Directory: Homebrew typically places the PostgreSQL data directory in
/usr/local/var/postgres.
Step 5: Managing PostgreSQL with Homebrew Services
- Stop PostgreSQL:
bash
brew services stop postgresql
- Restart PostgreSQL:
bash
brew services restart postgresql
- Unlink and Reinstall (if needed): If you encounter persistent issues or want to switch versions (though Homebrew typically manages one version at a time easily), you can unlink and reinstall:
bash
brew uninstall postgresql
brew install postgresql
Advanced Installation: PostgreSQL with Docker
For users who require maximum flexibility, isolation, or version management, Docker is an excellent choice. This method involves running PostgreSQL within a container.
Step 1: Install Docker Desktop for Mac
If you don’t have Docker Desktop installed, download it from the official Docker website (https://www.docker.com/products/docker-desktop/) and follow the installation instructions.
Step 2: Pull the Official PostgreSQL Docker Image
Open your Terminal and pull the latest official PostgreSQL image:
docker pull postgres
You can specify a version if needed, for example: docker pull postgres:14.
Step 3: Run a PostgreSQL Container
To run a PostgreSQL container, you’ll use the docker run command. Here’s a common example:
docker run --name my-postgres-container -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
Let’s break down this command:
docker run: Command to create and start a new container.--name my-postgres-container: Assigns a recognizable name to your container.-e POSTGRES_PASSWORD=mysecretpassword: Sets an environment variable to define the superuser (postgres) password. Replacemysecretpasswordwith a strong, unique password.-d: Runs the container in detached mode (in the background).-p 5432:5432: Maps port 5432 on your host machine to port 5432 inside the container. This allows you to connect to PostgreSQL from your Mac.postgres: Specifies the Docker image to use.
Step 4: Connect to the Containerized PostgreSQL
Once the container is running, you can connect to it using psql or a GUI tool.
-
Using
psql:psql -h localhost -p 5432 -U postgresYou will be prompted for the password you set (
mysecretpasswordin the example). -
Using pgAdmin: In pgAdmin, create a new server connection with:
- Hostname:
localhost - Port:
5432 - Username:
postgres - Password:
mysecretpassword(or whatever you set)
- Hostname:
Step 5: Managing Docker Containers
- List running containers:
bash
docker ps
- Stop the container:
bash
docker stop my-postgres-container
- Start the container:
bash
docker start my-postgres-container
- Remove the container (data will be lost unless volumes are used):
bash
docker rm my-postgres-container
For persistent storage, you would typically use Docker volumes in yourdocker runcommand.

Conclusion
Installing PostgreSQL on your Mac can be achieved through several robust methods, each catering to different user needs and technical preferences. Whether you opt for the straightforward graphical installer from PGDG, the efficient command-line approach with Homebrew, or the isolated power of Docker, you’ll be well-equipped to leverage PostgreSQL’s capabilities for your development and data management tasks. Understanding these options allows you to choose the installation that best fits your workflow and ensures a smooth and productive experience with this leading database system.
