If you want to install a PostgreSQL database on macOS, you can follow the steps in this guide.
In summary, the steps are:
- Download the installation package
- Install the package
- Connect using an IDE such as pgAdmin
We’ll go through these steps in detail in this post.
To install Postgres on macOS, we first need to download the installation package.
Step 1: Visit the PostgreSQL macOS Package page here: https://www.postgresql.org/download/macosx/
Step 2: Click on the “Download the installer” link near the top of the page.
You’ll be taken to a site called Enterprise DB which hosts the Postgres packages.
Step 3: Click on the button under the Mac OS X column for the version you would like. For this tutorial, we’ll use the latest version, which is 14.5.
Step 4: Select a location to save the installation package and click Save.
The file will then begin downloading. It’s about 300 MB so may take a little while, depending on your connection speed.
An alternative to using this package is to use Homebrew. I’ll create a separate guide for doing that.
Install the Package
Once the installation package is downloaded, you can open it.
Step 1: Open the downloaded file.
After it is verified, a folder will be displayed with another file.
Step 2: Double-click on the postgres file in the window.
Step 3: If a warning appears about the file being downloaded from the Internet, click Open.
Step 4: Enter your password if you are prompted.
Once the splash screen has loaded, you’ll see the PostgreSQL Setup Wizard
Step 5: Click Next on the welcome screen.
You’ll see the Installation Directory screen.
Step 6: Leave the default directory and click Next.
You’ll see the Select Components screen.
Step 7: Click Next to install all components.
You can deselect any that you don’t want, but you can just leave the defaults selected if you want.
You can click on any of the components to see a description:
- PostgreSQL Server: PostgreSQL database server
- pgAdmin 4: pgAdmin 4 is a graphical user interface for managing and working with PostgreSQL databases and servers.
- Stack Builder: Stack Builder may be used to download and install additional tools, drivers, and applications to complement your PostgreSQL installation.
- Command Line Tools: This option installs command line tools and client libraries such as libpq, ecpg, pg_basebackup, pg_dump, pg_restore, pg_bench and more. The command line tools are required option when installing the PostgreSQL Database Server or pgAdmin 4.
Once you click Next, you’ll see the Data Directory screen.
Step 8: Leave the default Data Directory and click Next.
You’ll see the Password screen.
Step 9: Enter a password to use for the postgres user on the database, and click Next.
You’ll need to remember this for when you connect to the database later in this guide.
Once you click Next, you’ll see the Port screen.
By default, Postgres will use port 5432.
If you get an error about the port being in use, you can use a different port such as 5433.
Step 10: Click Next on the port screen.
You’ll then see the Advanced Options screen.
Step 11: Leave the default locale selected, and click Next.
You’ll then see the Pre Installation Summary screen.
Step 12: Click Next.
You’ll then see the Ready to Install screen.
Step 13: Click Next to begin the installation.
The installation will then begin.
The installation should complete in about 2 minutes.
Once the installation is complete, you’ll see the Completing the Setup Wizard screen.
It says that setup is complete and asks if you want to run Stack Builder.
Step 14: Unselect “Launch Stack Builder” and click Finish.
PostgreSQL is now installed on your Mac!
The next step is to connect to the database.
Connect Using pgAdmin
Now the database is installed, we can connect to it and begin working with it.
You can do this using the pgAdmin tool that was installed along with Postgres, or use a command line tool, or use another IDE such as DBeaver.
In this guide, we’ll connect using pgAdmin.
Step 1: In Finder, browse to Applications, then PostgreSQL 14.
Step 2: Open the “pgAdmin 4” application.
Alternatively, you can launch this using Spotlight.
pgAdmin will then open.
You’ll see a splash screen for a moment while it loads.
pgAdmin will then open.
You’ll be prompted to provide a master password. This is a password used by pgAdmin to access all of the databases that you set up. It’s different to the postgres password you specified when you installed postgres.
The master password is strongly recommended by the pgAdmin team because of the way the application works and to add more security.
Step 3: Enter a master password you want to use, and click OK.
The Postgres main screen will then be displayed.
Step 4: Expand the Servers section on the left of the screen.
There should be at least one entry shown here. pgAdmin will automatically detect any Postgres installations and create a server entry (which represents a database connection).
In this example, there is:
- PostgreSQL 13 – an older version I had on my computer
- PostgreSQL 14 – the version I just installed
- Postgres Demo – a server I had already set up
- Postgres Docker – a server I set up for connecting to Docker. (Related: how to set up Postgres using Docker)
The PostgreSQL 14 entry is the one we want to use and the only one that should appear in your list.
Step 5: Double-click on the PostgreSQL 14 entry.
You’ll be prompted to enter the password.
Step 6: Enter the password you provided during the PostgreSQL installation – the one you needed to remember for now.
Step 7: Check the Save Password box if you want pgAdmin to store the password, so you don’t have to enter it each time you want to connect.
Step 8: Click OK.
After a moment, the database will be connected.
The PostgreSQL 14 icon in the Server list will change to an elephant (the Postgres logo), and will expand to show databases and other items.
We’re now done. That’s how you install postgres on a Mac.
If you want to learn more about SQL, including PostgreSQL, and databases, subscribe to my newsletter below and I’ll send you some SQL Cheat Sheets,