1- Install Homebrew
-
1.1- If you don't have Homebrew already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
2.1- Use Homebrew to install Postgres:
brew update && brew install postgresql@17
-
2.2- Review the "Caveats" section of the installation output, and add Postgres to the PATH:
echo 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"' >> ~/.zshrc
-
2.3- Reload the Terminal:
source ~/.zshrc
-
2.4- Start the Postgres service on every computer startup:
brew services start postgresql@17
-
2.5- Verify that the service is running:
brew services list
-
2.6- Extras (Do NOT do this):
# ⚠️ Do NOT do this # The above should work fine # Only in case there are PATH issues brew link postgresql@17 --force
# ⚠️ Do NOT do this # It's just FYI brew services stop postgresql@17 brew services restart postgresql@17
-
3.1- Check versions:
postgres --version psql --version
-
3.2- Connect to the
postgres
database:psql postgres
-
3.3- Disconnect from the
postgres
database:\q
-
4.1- The quotes around the table name enforce case sensitivity (Prisma likes CamelCase table names):
CREATE TABLE IF NOT EXISTS "User" ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT NOW() ); INSERT INTO "User" (name, email) VALUES ('Alice', '[email protected]');
-
5.1- Create a
test_db
database:createdb test_db
(Alternatively, create a
test_db
database using PgAdmin4.) -
5.2- Execute the
create_user_table.sql
file to create the "User" table and seed some data:psql -d test_db -f create_user_table.sql
-
5.3- Connect to the
test_db
database:psql test_db
-
5.4- Run a query:
SELECT * FROM "User";
-
5.5- Disconnect from the
test_db
database:\q
-
5.6- Delete the
test_db
database:dropdb test_db
(Alternatively, delete the
test_db
database using PgAdmin4.)
6- Install PgAdmin4
-
6.1- Use Homebrew to install PgAdmin4:
brew install --cask pgadmin4