Install PostgreSQL on MacOS

PostgreSQL is a powerful, open-source relational database system. It’s available on all major operating systems, and has a proven track record of reliability and extensibility. PostgreSQL has been proven to be highly scalable both in the quantity of data it can manage and in the number of concurrent users it can accommodate.

Let’s get it installed on MacOS.

Install PostgreSQL on Mac with Homebrew

Homebrew is a popular package manager for MacOS. A package manager provides the ability to quickly install packages, their dependency packages, and keep the packages up to date. “Packages” are software libraries and executables generally runnable from a command-line interface.

1. Install Homebrew

While we will use Homebrew to install PostgreSQL and its dependencies, we first need to install the Homebrew package itself. If you do not already have Homebrew installed, run the following from a MacOS commandline:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Install PostgreSQL

$ brew update
$ brew install postgresql
$ postgres --version

3. Start the database server

Use the command brew services to start the Postgres server.

$ brew services start postgres

4. Create a database

brew services automatically creates a database named postgres. Make an additional database named by your MacOS username with the following command:

$ createdb $USER

References

Managing Postgres users and privileges: https://kb.objectrocket.com/postgresql/how-to-list-users-in-postgresql-782

PostgreSQL Security Best Practices: https://resources.2ndquadrant.com/hubfs/Whitepaper PDFs/PostgreSQL_Security_Best_Practices_Whitepaper.pdf

This article was originally posted as Install PostgreSQL on MacOS at alexa-anderson.com/blog.

alexa anderson

About the Author

Alexa Anderson is an engineer and evangelist with a penchant for making products geared for progress and achievement. When not writing software, Alexa spends her time curating content and sharing her discoveries.