Installing PostgreSQL on macOS with HomebrewInstalling PostgreSQL on macOS with HomebrewInstalling PostgreSQL on macOS with Homebrew

2024::03::11
2 min
AUTHOR:Z.SHINCHVEN

Introduction

PostgreSQL, a powerful open-source relational database management system, can be installed on macOS using Homebrew, a package manager for macOS.

Installation

  1. Install Homebrew by running:

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

    brew install postgresql
    

Starting, Stopping, and Restarting the Service

  1. Start PostgreSQL:

    brew services start postgresql
    
  2. Stop PostgreSQL:

    brew services stop postgresql
    
  3. Restart PostgreSQL:

    brew services restart postgresql
    

Setting a Password

  1. Set a password for the default user postgres:
    sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'new_password';"
    

Connecting to the Service

  1. Connect to PostgreSQL using the default user postgres and the password you set:
    psql -U postgres -d postgres
    

Customizing the Configuration File

  1. Edit the configuration file /usr/local/etc/postgresql/*.conf:

    sudo vi /usr/local/etc/postgresql/*.conf
    
  2. Make desired changes to the configuration parameters. For example, to change the listen address:

    listen_addresses = '*'
    
  3. Save and close the file.

  4. Restart PostgreSQL to apply the changes:

    brew services restart postgresql
    

Conclusion

Installing and configuring PostgreSQL on macOS using Homebrew is straightforward. By following these steps, you can easily set up a PostgreSQL database for your projects or applications. Remember to secure your database by setting a strong password and customizing the configuration file as needed.

RackNerd Billboard Banner
Share Node:

RELATED_DATA_STREAMS

SCANNING_DATABASE_FOR_CORRELATIONS...