Setup - Mac M1
1
1. Install PostgreSQL using Homebrew
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)"
Install PostgreSQL:
Run the following command in the terminal:
brew install postgresql
Start PostgreSQL Service:
Start the PostgreSQL service:
brew services start postgresql
Verify Installation:
Check the version to ensure it is installed correctly:
psql --version
2. Initialize the Database
Initialize the database:
initdb /usr/local/var/postgresStart the PostgreSQL Server:
pg_ctl -D /usr/local/var/postgres start
3. Create a User and Database
Access PostgreSQL Shell:
Create a New User:
Create a New Database:
Grant Privileges:
Exit the Shell:
4. Configure PostgreSQL
Edit
postgresql.conf(optional for specific configurations):Locate the file:
Adjust settings like
listen_addressesto allow remote connections if needed.
Restart the Service:
5. Connect to PostgreSQL
From the Command Line:
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
Open your terminal.
Run the following command to install pgAdmin:
2. Launch pgAdmin
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
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.
After setting the master password, you'll see the pgAdmin interface.
4. Connect pgAdmin to PostgreSQL
In the pgAdmin interface, click on "Add New Server" (top-left corner).
Fill in the details:
General Tab:
Name: Enter a name for your server (e.g.,
Local PostgreSQL).
Connection Tab:
Host name/address:
localhostPort:
5432(default PostgreSQL port)Maintenance Database:
postgresUsername: Your PostgreSQL username (default is
postgres).Password: Your PostgreSQL password.
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)
Ensure PostgreSQL is Running:
Verify that the PostgreSQL service is running:
If it's not running, start it:
Check the Host and Port:
Make sure the
postgresql.conffile allows connections:Set
listen_addressesto:
Restart PostgreSQL:
Last updated