PostgreSQL Tutorial

Data Types

Querying & Filtering Data

Managing Tables

Modifying Data

Conditionals

Control Flow

Transactions & Constraints

Working with JOINS & Schemas

Roles & Permissions

Working with Sets

Subquery & CTEs

User-defined Functions

Important In-Built Functions

PostgreSQL PL/pgSQL

Variables & Constants

Stored Procedures

Working with Triggers

Working with Views & Indexes

Errors & Exception Handling

Install PostgreSQL on Mac

To install PostgreSQL on macOS, you have a few different options. The most popular ones are:

  1. Homebrew
  2. Postgres.app
  3. Official distribution from PostgreSQL's website

Here's how you can use each of these methods:

1. Homebrew:

If you haven't installed Homebrew yet, you can do so by following the instructions on their official website or using the following command:

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

Once you have Homebrew installed, you can install PostgreSQL:

brew update
brew install postgresql

After installation, you can start the PostgreSQL service:

brew services start postgresql

2. Postgres.app:

Postgres.app is a macOS application that packages and manages a full-featured PostgreSQL installation in a single package.

  1. Go to the official website.
  2. Download the application.
  3. Drag the application to your Applications folder.
  4. Double-click on Postgres.app to start.

This application will run PostgreSQL on its default port (5432) and include other utilities like psql.

3. Official distribution:

  1. Go to the official PostgreSQL download page for macOS.
  2. Follow the interactive installer by EnterpriseDB. This installer provides a GUI to install and configure your PostgreSQL server.

Regardless of the method you choose, you'll probably want to set up the PATH for command line tools. If you choose the Homebrew option, the path is set up automatically. For Postgres.app, you'll want to add /Applications/Postgres.app/Contents/Versions/latest/bin to your PATH.

After installation, you can check if PostgreSQL is running by using the command:

psql -U postgres

This will log you into the PostgreSQL shell. If you encounter no errors, then PostgreSQL is installed and running properly.