Setup - Mac M1

1

1. Install PostgreSQL using Homebrew

  1. Install Homebrew (if you don't have it installed):

    • Open the terminal and run:

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

    • Run the following command in the terminal:

      brew install postgresql
  3. Start PostgreSQL Service:

    • Start the PostgreSQL service:

      brew services start postgresql
  4. Verify Installation:

    • Check the version to ensure it is installed correctly:

      psql --version

2. Initialize the Database

  1. Initialize the database:

    initdb /usr/local/var/postgres
  2. Start the PostgreSQL Server:

    pg_ctl -D /usr/local/var/postgres start

3. Create a User and Database

  1. Access PostgreSQL Shell:

  2. Create a New User:

  3. Create a New Database:

  4. Grant Privileges:

  5. Exit the Shell:


4. Configure PostgreSQL

  1. Edit postgresql.conf (optional for specific configurations):

    • Locate the file:

    • Adjust settings like listen_addresses to allow remote connections if needed.

  2. Restart the Service:


5. Connect to PostgreSQL

  1. From the Command Line:

  2. Using a GUI Tool:

    • You can use tools like pgAdmin, Postico, or DBeaver for a graphical interface to manage your PostgreSQL databases.


6. (Optional) Install pgAdmin

  • Download and install pgAdmin for a GUI-based interaction with PostgreSQL.


2

PgAdmin setup


1. Install pgAdmin using Homebrew

  1. Open your terminal.

  2. Run the following command to install pgAdmin:


2. Launch pgAdmin

  1. After installation, you can find pgAdmin in your Applications folder.

    • Open it directly by navigating to Applications > pgAdmin 4.

    • Alternatively, run it from the terminal:


3. Initial Setup

  1. When you open pgAdmin for the first time, it will ask for a Master Password to secure your configurations:

    • Create a password and remember it.

  2. After setting the master password, you'll see the pgAdmin interface.


4. Connect pgAdmin to PostgreSQL

  1. In the pgAdmin interface, click on "Add New Server" (top-left corner).

  2. Fill in the details:

    • General Tab:

      • Name: Enter a name for your server (e.g., Local PostgreSQL).

    • Connection Tab:

      • Host name/address: localhost

      • Port: 5432 (default PostgreSQL port)

      • Maintenance Database: postgres

      • Username: Your PostgreSQL username (default is postgres).

      • Password: Your PostgreSQL password.

  3. Click Save.


5. Verify the Connection

  • If everything is configured correctly, you should see your PostgreSQL server in the left panel of the pgAdmin interface.

  • You can expand it to see databases, schemas, tables, etc.


6. Troubleshooting (if needed)

  1. Ensure PostgreSQL is Running:

    • Verify that the PostgreSQL service is running:

      If it's not running, start it:

  2. Check the Host and Port:

    • Make sure the postgresql.conf file allows connections:

      Set listen_addresses to:

  3. Restart PostgreSQL:


Last updated