TigerData logo
TigerData logo
  • Product

    Tiger Cloud

    Robust elastic cloud platform for startups and enterprises

    Agentic Postgres

    Postgres for Agents

    TimescaleDB

    Postgres for time-series, real-time analytics and events

  • Docs
  • Pricing

    Pricing

    Enterprise Tier

  • Developer Hub

    Changelog

    Benchmarks

    Blog

    Community

    Customer Stories

    Events

    Support

    Integrations

    Launch Hub

  • Company

    Contact us

    About

    Timescale

    Partners

    Security

    Careers

Log InTry for free
Home
AWS Time-Series Database: Understanding Your OptionsStationary Time-Series AnalysisThe Best Time-Series Databases ComparedTime-Series Analysis and Forecasting With Python Alternatives to TimescaleWhat Are Open-Source Time-Series Databases—Understanding Your OptionsWhy Consider Using PostgreSQL for Time-Series Data?Time-Series Analysis in RWhat Is Temporal Data?What Is a Time Series and How Is It Used?Is Your Data Time Series? Data Types Supported by PostgreSQL and TimescaleUnderstanding Database Workloads: Variable, Bursty, and Uniform PatternsHow to Work With Time Series in Python?Tools for Working With Time-Series Analysis in PythonGuide to Time-Series Analysis in PythonUnderstanding Autoregressive Time-Series ModelingCreating a Fast Time-Series Graph With Postgres Materialized Views
Understanding PostgreSQLOptimizing Your Database: A Deep Dive into PostgreSQL Data TypesUnderstanding FROM in PostgreSQL (With Examples)How to Address ‘Error: Could Not Resize Shared Memory Segment’ How to Install PostgreSQL on MacOSUnderstanding FILTER in PostgreSQL (With Examples)Understanding GROUP BY in PostgreSQL (With Examples)PostgreSQL Join Type TheoryA Guide to PostgreSQL ViewsStructured vs. Semi-Structured vs. Unstructured Data in PostgreSQLUnderstanding Foreign Keys in PostgreSQLUnderstanding PostgreSQL User-Defined FunctionsUnderstanding PostgreSQL's COALESCE FunctionUnderstanding SQL Aggregate FunctionsUsing PostgreSQL UPDATE With JOINHow to Install PostgreSQL on Linux5 Common Connection Errors in PostgreSQL and How to Solve ThemUnderstanding HAVING in PostgreSQL (With Examples)How to Fix No Partition of Relation Found for Row in Postgres DatabasesHow to Fix Transaction ID Wraparound ExhaustionUnderstanding LIMIT in PostgreSQL (With Examples)Understanding PostgreSQL FunctionsUnderstanding ORDER BY in PostgreSQL (With Examples)Understanding WINDOW in PostgreSQL (With Examples)Understanding PostgreSQL WITHIN GROUPPostgreSQL Mathematical Functions: Enhancing Coding EfficiencyUnderstanding DISTINCT in PostgreSQL (With Examples)Using PostgreSQL String Functions for Improved Data AnalysisData Processing With PostgreSQL Window FunctionsPostgreSQL Joins : A SummaryUnderstanding OFFSET in PostgreSQL (With Examples)Understanding PostgreSQL Date and Time FunctionsWhat Is Data Compression and How Does It Work?What Is Data Transformation, and Why Is It Important?Understanding the Postgres string_agg FunctionWhat Is a PostgreSQL Left Join? And a Right Join?Understanding PostgreSQL SELECTSelf-Hosted or Cloud Database? A Countryside Reflection on Infrastructure ChoicesUnderstanding ACID Compliance Understanding percentile_cont() and percentile_disc() in PostgreSQLUnderstanding PostgreSQL Conditional FunctionsUnderstanding PostgreSQL Array FunctionsWhat Characters Are Allowed in PostgreSQL Strings?Understanding WHERE in PostgreSQL (With Examples)What Is a PostgreSQL Full Outer Join?What Is a PostgreSQL Cross Join?What Is a PostgreSQL Inner Join?Data Partitioning: What It Is and Why It MattersStrategies for Improving Postgres JOIN PerformanceUnderstanding the Postgres extract() FunctionUnderstanding the rank() and dense_rank() Functions in PostgreSQL
Guide to PostgreSQL PerformanceHow to Reduce Bloat in Large PostgreSQL TablesDesigning Your Database Schema: Wide vs. Narrow Postgres TablesBest Practices for Time-Series Data Modeling: Single or Multiple Partitioned Table(s) a.k.a. Hypertables Best Practices for (Time-)Series Metadata Tables A Guide to Data Analysis on PostgreSQLA Guide to Scaling PostgreSQLGuide to PostgreSQL SecurityHandling Large Objects in PostgresHow to Query JSON Metadata in PostgreSQLHow to Query JSONB in PostgreSQLHow to Use PostgreSQL for Data TransformationOptimizing Array Queries With GIN Indexes in PostgreSQLPg_partman vs. Hypertables for Postgres PartitioningPostgreSQL Performance Tuning: Designing and Implementing Your Database SchemaPostgreSQL Performance Tuning: Key ParametersPostgreSQL Performance Tuning: Optimizing Database IndexesDetermining the Optimal Postgres Partition SizeNavigating Growing PostgreSQL Tables With Partitioning (and More)Top PostgreSQL Drivers for PythonWhen to Consider Postgres PartitioningGuide to PostgreSQL Database OperationsUnderstanding PostgreSQL TablespacesWhat Is Audit Logging and How to Enable It in PostgreSQLGuide to Postgres Data ManagementHow to Index JSONB Columns in PostgreSQLHow to Monitor and Optimize PostgreSQL Index PerformanceSQL/JSON Data Model and JSON in SQL: A PostgreSQL PerspectiveA Guide to pg_restore (and pg_restore Example)PostgreSQL Performance Tuning: How to Size Your DatabaseAn Intro to Data Modeling on PostgreSQLExplaining PostgreSQL EXPLAINWhat Is a PostgreSQL Temporary View?A PostgreSQL Database Replication GuideHow to Compute Standard Deviation With PostgreSQLHow PostgreSQL Data Aggregation WorksBuilding a Scalable DatabaseRecursive Query in SQL: What It Is, and How to Write OneGuide to PostgreSQL Database DesignHow to Use Psycopg2: The PostgreSQL Adapter for Python
Best Practices for Scaling PostgreSQLHow to Design Your PostgreSQL Database: Two Schema ExamplesHow to Handle High-Cardinality Data in PostgreSQLHow to Store Video in PostgreSQL Using BYTEABest Practices for PostgreSQL Database OperationsHow to Manage Your Data With Data Retention PoliciesBest Practices for PostgreSQL AggregationBest Practices for Postgres Database ReplicationHow to Use a Common Table Expression (CTE) in SQLBest Practices for Postgres Data ManagementBest Practices for Postgres PerformanceBest Practices for Postgres SecurityBest Practices for PostgreSQL Data AnalysisTesting Postgres Ingest: INSERT vs. Batch INSERT vs. COPYHow to Use PostgreSQL for Data Normalization
PostgreSQL Extensions: amcheckPostgreSQL Extensions: Unlocking Multidimensional Points With Cube PostgreSQL Extensions: hstorePostgreSQL Extensions: ltreePostgreSQL Extensions: Secure Your Time-Series Data With pgcryptoPostgreSQL Extensions: pg_prewarmPostgreSQL Extensions: pgRoutingPostgreSQL Extensions: pg_stat_statementsPostgreSQL Extensions: Install pg_trgm for Data MatchingPostgreSQL Extensions: Turning PostgreSQL Into a Vector Database With pgvectorPostgreSQL Extensions: Database Testing With pgTAPPostgreSQL Extensions: PL/pgSQLPostgreSQL Extensions: Using PostGIS and Timescale for Advanced Geospatial InsightsPostgreSQL Extensions: Intro to uuid-ossp
Columnar Databases vs. Row-Oriented Databases: Which to Choose?Data Analytics vs. Real-Time Analytics: How to Pick Your Database (and Why It Should Be PostgreSQL)How to Choose a Real-Time Analytics DatabaseUnderstanding OLTPOLAP Workloads on PostgreSQL: A GuideHow to Choose an OLAP DatabasePostgreSQL as a Real-Time Analytics DatabaseWhat Is the Best Database for Real-Time AnalyticsHow to Build an IoT Pipeline for Real-Time Analytics in PostgreSQL
When Should You Use Full-Text Search vs. Vector Search?HNSW vs. DiskANNA Brief History of AI: How Did We Get Here, and What's Next?A Beginner’s Guide to Vector EmbeddingsPostgreSQL as a Vector Database: A Pgvector TutorialUsing Pgvector With PythonHow to Choose a Vector DatabaseVector Databases Are the Wrong AbstractionUnderstanding DiskANNA Guide to Cosine SimilarityStreaming DiskANN: How We Made PostgreSQL as Fast as Pinecone for Vector DataImplementing Cosine Similarity in PythonVector Database Basics: HNSWVector Database Options for AWSVector Store vs. Vector Database: Understanding the ConnectionPgvector vs. Pinecone: Vector Database Performance and Cost ComparisonHow to Build LLM Applications With Pgvector Vector Store in LangChainHow to Implement RAG With Amazon Bedrock and LangChainRetrieval-Augmented Generation With Claude Sonnet 3.5 and PgvectorRAG Is More Than Just Vector SearchPostgreSQL Hybrid Search Using Pgvector and CohereImplementing Filtered Semantic Search Using Pgvector and JavaScriptRefining Vector Search Queries With Time Filters in Pgvector: A TutorialUnderstanding Semantic SearchWhat Is Vector Search? Vector Search vs Semantic SearchText-to-SQL: A Developer’s Zero-to-Hero GuideNearest Neighbor Indexes: What Are IVFFlat Indexes in Pgvector and How Do They WorkBuilding an AI Image Gallery With OpenAI CLIP, Claude Sonnet 3.5, and Pgvector
Understanding IoT (Internet of Things)A Beginner’s Guide to IIoT and Industry 4.0Storing IoT Data: 8 Reasons Why You Should Use PostgreSQLMoving Past Legacy Systems: Data Historian vs. Time-Series DatabaseWhy You Should Use PostgreSQL for Industrial IoT DataHow to Choose an IoT DatabaseHow to Simulate a Basic IoT Sensor Dataset on PostgreSQLFrom Ingest to Insights in Milliseconds: Everactive's Tech Transformation With TimescaleHow Ndustrial Is Providing Fast Real-Time Queries and Safely Storing Client Data With 97 % CompressionHow Hopthru Powers Real-Time Transit Analytics From a 1 TB Table Migrating a Low-Code IoT Platform Storing 20M Records/DayHow United Manufacturing Hub Is Introducing Open Source to ManufacturingBuilding IoT Pipelines for Faster Analytics With IoT CoreVisualizing IoT Data at Scale With Hopara and TimescaleDB
What Is ClickHouse and How Does It Compare to PostgreSQL and TimescaleDB for Time Series?Timescale vs. Amazon RDS PostgreSQL: Up to 350x Faster Queries, 44 % Faster Ingest, 95 % Storage Savings for Time-Series DataWhat We Learned From Benchmarking Amazon Aurora PostgreSQL ServerlessTimescaleDB vs. Amazon Timestream: 6,000x Higher Inserts, 5-175x Faster Queries, 150-220x CheaperHow to Store Time-Series Data in MongoDB and Why That’s a Bad IdeaPostgreSQL + TimescaleDB: 1,000x Faster Queries, 90 % Data Compression, and Much MoreEye or the Tiger: Benchmarking Cassandra vs. TimescaleDB for Time-Series Data
Alternatives to RDSWhy Is RDS so Expensive? Understanding RDS Pricing and CostsEstimating RDS CostsHow to Migrate From AWS RDS for PostgreSQL to TimescaleAmazon Aurora vs. RDS: Understanding the Difference
5 InfluxDB Alternatives for Your Time-Series Data8 Reasons to Choose Timescale as Your InfluxDB Alternative InfluxQL, Flux, and SQL: Which Query Language Is Best? (With Cheatsheet)What InfluxDB Got WrongTimescaleDB vs. InfluxDB: Purpose Built Differently for Time-Series Data
5 Ways to Monitor Your PostgreSQL DatabaseHow to Migrate Your Data to Timescale (3 Ways)Postgres TOAST vs. Timescale CompressionBuilding Python Apps With PostgreSQL: A Developer's GuideData Visualization in PostgreSQL With Apache SupersetMore Time-Series Data Analysis, Fewer Lines of Code: Meet HyperfunctionsIs Postgres Partitioning Really That Hard? An Introduction To HypertablesPostgreSQL Materialized Views and Where to Find ThemTimescale Tips: Testing Your Chunk Size
Postgres cheat sheet
HomeTime series basicsPostgres basicsPostgres guidesPostgres best practicesPostgres extensionsPostgres for real-time analytics
Sections

Postgres overview

Understanding PostgreSQLOptimizing Your Database: A Deep Dive into PostgreSQL Data Types

Postgres errors

How to Address ‘Error: Could Not Resize Shared Memory Segment’ 5 Common Connection Errors in PostgreSQL and How to Solve ThemHow to Fix No Partition of Relation Found for Row in Postgres DatabasesHow to Fix Transaction ID Wraparound Exhaustion

Install postgres

How to Install PostgreSQL on LinuxHow to Install PostgreSQL on MacOS

Postgres clauses

Understanding FROM in PostgreSQL (With Examples)Understanding FILTER in PostgreSQL (With Examples)Understanding HAVING in PostgreSQL (With Examples)Understanding GROUP BY in PostgreSQL (With Examples)Understanding LIMIT in PostgreSQL (With Examples)Understanding ORDER BY in PostgreSQL (With Examples)Understanding WINDOW in PostgreSQL (With Examples)Understanding PostgreSQL WITHIN GROUPUnderstanding DISTINCT in PostgreSQL (With Examples)Understanding WHERE in PostgreSQL (With Examples)Understanding OFFSET in PostgreSQL (With Examples)

Postgres joins

PostgreSQL Joins : A SummaryWhat Is a PostgreSQL Full Outer Join?What Is a PostgreSQL Cross Join?What Is a PostgreSQL Inner Join?What Is a PostgreSQL Left Join? And a Right Join?PostgreSQL Join Type TheoryStrategies for Improving Postgres JOIN Performance

Postgres operations

A Guide to PostgreSQL ViewsData Partitioning: What It Is and Why It MattersWhat Is Data Compression and How Does It Work?Self-Hosted or Cloud Database? A Countryside Reflection on Infrastructure Choices

More

Understanding ACID Compliance Structured vs. Semi-Structured vs. Unstructured Data in PostgreSQLUnderstanding Foreign Keys in PostgreSQL

Postgres functions

Understanding PostgreSQL FunctionsPostgreSQL Mathematical Functions: Enhancing Coding EfficiencyUsing PostgreSQL String Functions for Improved Data AnalysisData Processing With PostgreSQL Window FunctionsUnderstanding PostgreSQL Date and Time FunctionsUnderstanding the Postgres string_agg FunctionUnderstanding PostgreSQL User-Defined FunctionsUnderstanding PostgreSQL's COALESCE FunctionUnderstanding SQL Aggregate FunctionsUnderstanding percentile_cont() and percentile_disc() in PostgreSQLUnderstanding PostgreSQL Conditional FunctionsUnderstanding PostgreSQL Array FunctionsUnderstanding the Postgres extract() FunctionUnderstanding the rank() and dense_rank() Functions in PostgreSQL

Postgres statements

Understanding PostgreSQL SELECTUsing PostgreSQL UPDATE With JOINWhat Characters Are Allowed in PostgreSQL Strings?

Data analysis

What Is Data Transformation, and Why Is It Important?

Products

Time Series and Analytics AI and Vector Enterprise Plan Cloud Status Support Security Cloud Terms of Service

Learn

Documentation Blog Forum Tutorials Changelog Success Stories Time Series Database

Company

Contact Us Careers About Brand Community Code Of Conduct Events

Subscribe to the Tiger Data Newsletter

By submitting, you acknowledge Tiger Data's Privacy Policy

2025 (c) Timescale, Inc., d/b/a Tiger Data. All rights reserved.

Privacy preferences
LegalPrivacySitemap

Published at Apr 16, 2025

How to Install PostgreSQL on MacOS

Try for free

Start supercharging your PostgreSQL today.

Written by Semab Tariq

PostgreSQL is a widely used open-source database system trusted by developers and businesses worldwide. For two years in a row, it has been among the most loved databases in the Stack Overflow Developer Survey.

If you are new to PostgreSQL, the first step is installation. Some people assume that setting it up is complex, However, that's not true! Installing PostgreSQL is actually quite simple.

There are multiple ways to install PostgreSQL on macOS: you can use the EnterpriseDB installer, Postgres.app, Homebrew, and MacPorts. Each method has its own advantages:

  • EnterpriseDB installer provides advanced management tools.

  • Postgres.app offers a self-contained, GUI-based simple PostgreSQL setup.

  • Homebrew installs PostgreSQL with a minimal footprint, integrating seamlessly with macOS.

  • MacPorts offers a flexible and isolated PostgreSQL installation with robust dependency management.

In this guide, I'll walk you through each installation method step by step.

To instantly speed up your PostgreSQL database through automatic partitioning, a powerful hybrid row-columnar storage engine, and always up-to-date materialized views, try installing the TimescaleDB extension. TimescaleDB revs up PostgreSQL, expanding it for time series, real-time analytics, events, vector data, and other demanding workloads.

Installing PostgreSQL via EnterpriseDB Installers

EnterpriseDB (EDB) provides an official PostgreSQL installer for macOS, including various management tools. It is ideal for users who prefer a guided setup with a wizard and require additional PostgreSQL management tools, such as pgAdmin and StackBuilder (for downloading PostgreSQL extensions), to meet their business needs.

Download the installer

Visit the PostgreSQL installers download page and download the required PostgreSQL version. For this tutorial, I will download the PostgreSQL 16.6 installer.

This is what the download page for PostgreSQL installers looks like.

image

After selecting the desired PostgreSQL version, you will be redirected to the download page, and the download will start automatically.

image

Launch the installer

Once the download is complete, double-click the .dmg file and select the PostgreSQL-16.6-1.osx installer to launch it.

image

After clicking on the installer, you may see a warning since macOS often alerts users about potential risks when downloading apps from a browser instead of the App Store. However, since we downloaded the installer from a trusted source, you can simply click "Open" to proceed with the installation.

image

After clicking "Open," you may be prompted to enter your logged-in user's password. If a dialog appears, enter your password and press Enter. The installer will then launch, and you will see its home screen.

This is what the initial screen of the installer looks like. Click the "Next" button to continue with the installation configuration.

image

Choosing the PostgreSQL installation directory

Specify the installation directory for the PostgreSQL server.

If you want to change the path, enter your preferred location; otherwise, you can proceed with the default. Then, click "Next" to continue.

image

Selecting PostgreSQL installation components

Next, you will be asked to choose the components to install as part of the PostgreSQL setup. Here’s what each component includes:

  • PostgreSQL Server: The core database engine that stores and manages data.

  • pgAdmin 4: This web-based GUI tool manages and interacts with PostgreSQL databases.

  • Stack Builder: This utility helps you install additional PostgreSQL extensions.

  • Command Line Tools: This set of CLI utilities, including psql, can manage and query the database.

Select the components you want to install.

Note: PostgreSQL Server is required for installation.

Let's select all the options and click "Next" to proceed.

image

Setting the data directory path

On the next screen, you need to specify the data directory path for your PostgreSQL server.

What is the data directory?

The PostgreSQL data directory is where all database files, configurations, and transaction logs (WAL) are stored. It is defined by the data_directory parameter in postgresql.conf.

If you want to change the default path, specify your preferred location. Otherwise, you can proceed with the default setting.

Click "Next" to continue.

image

Setting the superuser password

On the next screen, you need to specify a password for the PostgreSQL superuser. 

By default, PostgreSQL creates a superuser named "postgres," and the password you set here will be used to connect to the database with postgres user.

What is a PostgreSQL superuser?

A PostgreSQL superuser has unrestricted access to all database operations, including administrative tasks and security-sensitive actions.

Enter your desired password. Click "Next" to continue.

image

Configuring the PostgreSQL port

On the next screen, you need to specify the port on which the PostgreSQL instance will listen for incoming connections.

Why is the port important?

PostgreSQL requires a port to accept client connections and enable communication between the database server and applications over the network using the TCP/IP protocol.

After selecting the port, click "Next" to continue.

image

Configuring locale settings

On the next screen, you will be prompted to set the locale for the database cluster.

What is locale in PostgreSQL?

The locale controls how text is sorted and displayed based on language and region. For example, in English, "z" comes after "a" in sorting, but in Swedish, "ä" is treated as a separate letter and appears at the end of the alphabet.

You should change the locale if your database needs to follow specific language or regional sorting and formatting rules.

Choose the appropriate locale and click "Next" to proceed.

image

Review installation settings

On the second-to-last screen, the installer will display a summary of all the settings you have selected for installing PostgreSQL. Review these details carefully, then click "Next."

image

Confirm and start the installation

The final screen confirms that PostgreSQL is ready to be installed on your machine. Click "Next" to start the installation process.

imageimage

Completing the installation

Once the installation is complete, you will be redirected to the final screen.

If you want to install additional components along with the PostgreSQL server, leave the Stack Builder checkbox selected and click "Finish."

If you don’t need additional components, uncheck the box and click "Finish" to complete the installation.

image

Congratulations! You have successfully installed the PostgreSQL server.

Verify the installation

To confirm that PostgreSQL is installed correctly, open the terminal on your Mac and run the following commands:

cd /Library/PostgreSQL/16/bin ./psql -d postgres -U postgres -h localhost -p 5432

When prompted, enter the password for the postgres user. If the installation is successful, you should be able to connect to PostgreSQL.

psql (16.6) Type "help" for help. postgres=# SELECT version(); Version --------------------------------------------------------------------- ---------------------------------------- PostgreSQL 16.6 on x86_64-apple-darwin23.6.0, compiled by Apple clang version 16.0.0 (clang-1600.0.26.4), 64-bit (1 row)

This confirms that PostgreSQL 16.6 is running and accessible.

Note: If you ever forget details like the port, data directory path, or other settings chosen during installation, you can find them in the installation_summary.log file inside your installation directory.

cat /Library/PostgreSQL/16/installation_summary.log.

Installing PostgreSQL via Postgres.app 

Postgres.app is a simple, native macOS application that provides a full-featured PostgreSQL installation in a single package. It is designed for developers, students, and macOS users who want an easy, hassle-free way to run PostgreSQL without dealing with complex configurations. 

With a one-click setup, it includes essential tools like psql and runs PostgreSQL as a background service, making it ideal for local development and testing.

Download the installer

Go to the Postgres.app download page and download the installer for your required PostgreSQL version.

image

Installing Postgres.app on macOS

After downloading the required PostgreSQL version (we'll install PostgreSQL 16), double-click the .dmg file, then drag and drop Postgres.app into the Applications folder. That’s it—installation is complete!

image

Connecting to PostgreSQL via Postgres.app

Open Postgres.app from the Applications folder to launch the setup wizard. Select the user you want to connect with, and it will open the macOS Terminal, where you will be connected to PostgreSQL.

Note: I changed my port to 5437 because another PostgreSQL instance was already using the default port (5432). To do this, I went to Settings, specified the new port, and then clicked "Start" to run PostgreSQL on the non-default port.

image

Verifying the PostgreSQL version

Once connected to PostgreSQL in the terminal, run the following query to check the server version.

"/Applications/Postgres.app/Contents/Versions/16/bin/psql" -p5432 "postgres" psql (16.6 (Postgres.app)) Type "help" for help. postgres=# select version();                                                               version                                                                ------------------------------------------------------------------------------------------------------------------------------------  PostgreSQL 16.6 (Postgres.app) on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit (1 row) postgres=# 

Installing PostgreSQL via Homebrew

Homebrew is a popular package manager for macOS that allows users to easily install and manage software from the command line. Developers and system administrators can use Homebrew to install PostgreSQL with a single command, making it a quick and efficient method for those comfortable with the terminal.

Installing Homebrew (if not installed)

If Homebrew is not already installed on your system, you can install it using the following command:

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

Installing PostgreSQL

Use this command to install PostgreSQL:

brew install postgresql@16

Note: Use the required version that you wish to install instead of 16. 

PostgreSQL will be installed under the following directory: /usr/local/var/ 

Start PostgreSQL service 

After installation, you can start the PostgreSQL service manually by running the following command:

brew services start postgresql@16

Verify the installation 

We can use the brew command to check the status of the PostgreSQL service.

brew services info postgresql@16 postgresql@16 (homebrew.mxcl.postgresql@16) Running: ✔ Loaded: ✔ Schedulable: ✘ User: mapmac PID: 8534

Connect with PostgreSQL

Navigate to the PostgreSQL installation directory and run the following command to connect to the PostgreSQL server.

cd /usr/local/Cellar/postgresql@16/16.6/bin mapmac@192 bin % ./psql postgres psql (16.6 (Homebrew)) Type "help" for help. postgres=# select version(); Version --------------------------------------------------------------------- ------------------------------------------------------- PostgreSQL 16.6 (Homebrew) on x86_64-apple-darwin23.6.0, compiled by Apple clang version 16.0.0 (clang-1600.0.26.4), 64-bit (1 row)

Installing PostgreSQL Using MacPorts

MacPorts is a package management system for macOS that simplifies the installation of Unix-based software, including PostgreSQL. It is ideal for developers who need a more customizable and isolated environment, as MacPorts installs software in /opt/local, keeping it separate from system files.

Compared to Homebrew, which installs packages in /usr/local (or /opt/homebrew on Apple Silicon) and integrates more with macOS, MacPorts offers better control over dependencies and multiple PostgreSQL versions. If you need a self-contained, flexible setup or work on projects requiring specific library versions, MacPorts is a great choice for installing PostgreSQL.

Install MacPorts (if not installed)

Visit the official MacPorts website to download the latest installer compatible with your system.

After downloading, open the MacPorts installer, which will guide you through the installation steps smoothly.

After installation, run the following command in your terminal to verify the installation. It will display the installed MacPort version on your system.

port version Version: 2.10.5

Install PostgreSQL and required packages

Run the following command to install PostgreSQL 16 and its server package:

sudo port install postgresql16 postgresql16-server

This will download and install PostgreSQL 16 along with the necessary dependencies.

Set PostgreSQL 16 as the default version

To ensure PostgreSQL 16 is used by default, run the following command, which sets PostgreSQL 16 as the default version for the postgresql command.

sudo port select postgresql postgresql16

Create the database directory

PostgreSQL requires a directory to store its database files. Create it using:

sudo mkdir -p /opt/local/var/db/postgresql16/defaultdbSet Directory Ownership

Change the ownership of the database directory to the postgres user. This step ensures PostgreSQL has the necessary permissions to access the directory.

sudo chown postgres:postgres /opt/local/var/db/postgresql16/defaultdb

Initialize the database

Run the following command to initialize the PostgreSQL database cluster. This sets up the necessary database files in the specified directory.

sudo -u postgres /bin/sh -c 'cd /opt/local/var/db/postgresql16 && /opt/local/lib/postgresql16/bin/initdb -D /opt/local/var/db/postgresql16/defaultdb'

Enable and start PostgreSQL server

By default, MacPorts does not start PostgreSQL automatically. To enable and start the PostgreSQL service, run

sudo port load postgresql16-server This ensures that PostgreSQL starts immediately and also launches at system startup.

Final verification

To check if PostgreSQL is running, use:

sudo -u postgres /opt/local/lib/postgresql16/bin/pg_ctl status -D /opt/local/var/db/postgresql16/defaultdb pg_ctl: server is running (PID: 18977) /opt/local/lib/postgresql16/bin/postgres "-D" "/opt/local/var/db/postgresql16/defaultdb"

Now, PostgreSQL is successfully installed and running on your system!

Conclusion 

This article explores four distinct methods for installing PostgreSQL on macOS: the EDB installer, Postgres.app, Homebrew, and MacPorts. It provides a detailed, step-by-step guide for each approach, outlining installation procedures, and configurations. By following this guide, you can efficiently deploy PostgreSQL on macOS and seamlessly integrate it into your development or production environment.

To instantly speed up your PostgreSQL database through automatic partitioning, a powerful hybrid row-columnar storage engine, and always up-to-date materialized views, try installing the TimescaleDB extension. TimescaleDB revs up PostgreSQL, expanding it for time series, real-time analytics, events, vector data, and other demanding workloads.

On this page

    Try for free

    Start supercharging your PostgreSQL today.