How to install PostgreSQL on macOS: 2 simple ways

Without a doubt, Windows is the key platform for the majority of database development and management solutions, and those related to PostgreSQL are no exception here. But we should never forget about the second most popular operating system— that's macOS, of course—and this is where we'd like to show you how to install PostgreSQL on a Mac, create databases, and start managing them using a specialized IDE called dbForge Studio for PostgreSQL.

About PostgreSQL

PostgreSQL is an enterprise-grade open-source relational database system that supports both relational and non-relational querying (the former is done via SQL, the latter via JSON). This system is renowned for being highly stable, scalable, and resilient, with more than 20 years of community development behind its back. Currently, it's one of the most popular database systems alongside MySQL, SQL Server, and Oracle Database, and it's a proven solution for countless applications from nearly every imaginable business domain.

The feature set of PostgreSQL includes multi-version concurrency control, point-in-time recovery, granular access controls, asynchronous replication, nested transactions, hot backups, tablespaces, a refined query planner/optimizer, and write-ahead logging. It is also known to provide extensive support for advanced data types, international character sets and multi-byte character encodings. Additionally, PostgreSQL is no stranger to effective performance optimization, not any worse than that of its commercial counterparts.

About macOS

Now here are a few words about Apple macOS, an operating system with probably the most loyal following one can get. Behind the fact that it's sleek and stylish, we shouldn't forget the exceptional levels of convenience in daily work, reliability, high performance, perfect integration with the native Apple hardware, and some of the richest capabilities an operating system can possibly offer.

That said, macOS is one of the most vital platforms for software development (and database development as well). Without further ado, let us show you the two ways of installing PostgreSQL on your Mac, show you how to connect to it, how to create your first database, how to fill it with data, and much more.

How to download and install PostgreSQL - a step-by-step guide

There are two ways to install PostgreSQL on your Mac. The first one is just your usual way of installing a program, when you download an installer file, open it, and follow the wizard's instructions. The second way is to install PostgreSQL on your Mac via Homebrew, a specialized package manager. The guide below will thoroughly cover both of these ways.

Download the PostgreSQL installer and install it on macOS

1. Download the PostgreSQL installer for macOS

Your first step is to download the PostgreSQL installer for macOS. Once you are on the Download PostgreSQL page, select the preferred version.

Download the PostgreSQL installer for macOS

2. Open the downloaded .dmg file

Open the downloaded .dmg file. Double-click the installer file within and click Open. If your Mac is locked with a password, you will be prompted to enter it.

Open the downloaded file

3. Open the installation wizard

The wizard opens. Click Next.

Open the installation wizard

4. Specify the installation directory

Specify the directory on your Mac where PostgreSQL will be installed and click Next.

Specify the installation directory

5. Select the required components

Keep the components you want to install selected and click Next.

Select the required components

6. Specify the data directory

Specify the directory where your data will be stored and click Next.

Specify the data directory

7. Provide a password

Provide a new password for the database superuser. Later on, you will use it to connect to PostgreSQL. After that, click Next.

Provide a password

8. Specify the port

Change the default port, if necessary, and click Next.

Specify the port

9. Select the locale

Select the locale that will be used by PostgreSQL. By default, it will use the locale of your current operating system.

Select the locale

10. Review the pre-installation summary

Review the pre-installation summary. Once you make sure everything is correct, click Next.

Review the pre-installation summary

11. Launch the installation

Now PostgreSQL is ready for installation. Click Next.

Launch the installation

12. Let the installation proceed

Give the installer a few minutes to conduct the installation.

Let the installation proceed

13. Complete the installation

Once the installation is complete, you will receive a notification. If you have previously selected Stack Builder to be installed, you will be prompted to launch it at exit. Afterwards, click Finish to exit the wizard. You have installed PostgreSQL on your Mac.

Complete the installation

Use Homebrew to install PostgreSQL on macOS

The alternative way to install PostgreSQL on your Mac is to use the Homebrew package manager.

1. Install Homebrew on your Mac

First, you need to make sure that Homebrew is installed on your Mac. To do that, open Terminal and run the brew command. If Homebrew is not installed, you will see a response like brew: command not found. In that case, to install Homebrew, run the following:

/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Homebrew will prompt you to enter your Mac user password. You won't see the characters as you type. Once you enter it, press Return to continue.

Then, just in case, you can run the brew update command to make sure you have the latest version at hand.

2. Install PostgreSQL via Homebrew

Next, you start installing PostgreSQL by running the following command:

brew install postgresql

The installation will commence. If something doesn't run smooth, Terminal will prompt you for additional actions.

Then give it a little time to be completed. What is great about this method is that Homebrew will automatically manage the dependencies required by PostgreSQL, and you won't have to install anything separately.

Once the installation is completed, you will see a message similar to the following:

Install PostgreSQL via Homebrew

First launch and connection to PostgreSQL

1. Start PostgreSQL via Terminal

After you install PostgreSQL on your Mac, you will be able to start it via Terminal using the following command:

brew services start postgresql

The result will be similar to this:

Start PostgreSQL via Terminal
Note
You can stop PostgreSQL using the brew services stop postgresql command.

2. Create a root user

Once your PostgreSQL is up and running, you can start configuring it by creating a root user with administrator privileges. To do that, run the following command:

psql postgres

The result will be as follows:

Create a root user

Need a reliable solution to manage your PostgreSQL databases?

Get the most comprehensive PostgreSQL IDE - dbForge Studio for PostgreSQL

How to manage PostgreSQL databases using a GUI client

But what if we suggest an alternative to Terminal that will make it all far easier and way faster? We believe that what you really need at this step is a multifunctional PostgreSQL GUI client that will help you create and manage databases. And we've got one for you! It's called dbForge Studio for PostgreSQL, and it delivers multiple tools for the development and management of your databases.

Although dbForge Studio is a classic Windows application, you can run it on macOS using a compatibility solution called CrossOver. You will find a detailed installation guide and a handy video tutorial on the Installation on Linux & macOS: Overview page of our documentation.

1. How to connect to a PostgreSQL database

Open dbForge Studio for PostgreSQL. In the Database menu, click New Connection.

How to connect to a PostgreSQL database

In the Database Connection Properties window that opens, specify the connection properties: Host, Port, User, and Password. Then select the required Database from the dropdown menu. After that, you can click Test Connection to verify that you have entered everything correctly. Finally, click Connect.

How to connect to a PostgreSQL database
Note
That besides PostgreSQL, you can establish a connection with quite a few compatible cloud databases, storage services, and search engines.

2. How to create and configure users in PostgreSQL

Creating a new user is just as easy. Click New SQL and enter the CREATE ROLE <username>; command. Run it with the Execute button. Once the Studio finishes the process, you will see the following notification: Query executed successfully.

How to create and configure users in PostgreSQL

Now let us show you a few options to diversify this command. The simplest way is to create a user with no password:

CREATE USER <username>;

And this is how you create a user with a password:

CREATE USER <username> WITH PASSWORD '<password>';

This is how you create a user with a password that is valid until a specified date:

CREATE USER <username> WITH PASSWORD '<password>' VALID UNTIL 'YYYY-MM-DD';

And this is how you create an account where the user can create databases:

CREATE USER <username> WITH PASSWORD '<password>' CREATEDB;

Similarly, you can configure users with the ALTER USER command. For instance, you can provide a user with the ability to create new users and databases:

ALTER USER <username> CREATEUSER CREATEDB;

Finally, this is how you delete a user:

DROP USER <username>

3. How to create and drop a PostgreSQL database

To create a new database, first, click New SQL.

How to create and drop a PostgreSQL database

In a new SQL document, enter the CREATE DATABASE <database name>; command with the name of your new database. Then click Execute.

How to create and drop a PostgreSQL database

In Database Explorer, click the Refresh button. Your new database will appear there under your connection. If you want to drop it, simply use the DROP DATABASE <database name>; command. Never easier!

How to create and drop a PostgreSQL database

4. How to export and import PostgreSQL data

Now let's see how to import PostgreSQL data into your new database. You have a whopping 10 formats to choose from, including TXT, XLS, XLSX, Google Sheets, MDB, XML, JSON, CSV, ODBC, and DBF. Go to the Database menu and click Import Data to open the wizard.

How to export and import PostgreSQL data

After you select a format, follow the wizard to configure the import settings. Note that the wizard tabs and available settings may vary depending on the format. After you configure everything as required, click Import, and wait a while for the process to be completed. Note that you can save your import settings as a template using the Save Template button.

How to export and import PostgreSQL data

Similarly, in the Database menu, click Export Data to get the export wizard ready. Here, you have even more formats to choose from, additionally including HTML, RTF, PDF, and SQL.

How to export and import PostgreSQL data
Download dbForge Studio for PostgreSQL
for a free 30-day trial today!
Now that you know all about installing and managing PostgreSQL databases on your Mac, we can only invite you one more time to download a FREE 30-day trial version of dbForge Studio for PostgreSQL and see it in action. We believe you will find its capabilities invaluable in your daily work.

How to uninstall PostgreSQL from macOS

1. Initiate the uninstallation in Terminal

To uninstall PostgreSQL from your Mac, open Terminal and run the following command: open /Library/PostgreSQL/15/uninstall-postgresql.app (the path is the same as the one you have specified during the installation). You will be prompted to enter your admin password. Once you do it, the wizard will open. Select the required option and click Next to launch the uninstallation.

Initiate the uninstallation in Terminal

2. Let the uninstallation proceed

The rest is extremely easy. Simply wait a few moments until PostgreSQL is uninstalled, and that's it!

Let the uninstallation proceed

3. Uninstall PostgreSQL from macOS via Homebrew

And if you installed PostgreSQL on your Mac via Homebrew, you might as well use it for uninstallation. To do that, stop the server (if it's running) and execute the brew uninstall postgresql command.

Uninstall PostgreSQL from macOS via Homebrew