set up postgres sql in pc mac

download postgressql application

Steps to Add psql to PATH

1. Edit Your Shell Configuration

Since you're using zsh, add the directory to your PATH in the ~/.zshrc file:
vim ~/.zshrc
Add the following line at the end of the file:
export PATH=$PATH:/Library/PostgreSQL/17/bi

2. Apply Changes

Reload your shell configuration:
.source ~/.zshrc

3. Verify psql Command

Check if psql is now available:
psql --ve
You should see the version of psql displayed.

4. Connect to PostgreSQL

Now you can try connecting to your PostgreSQL database:
psql -U devanshpc

1. List Existing Databases

Connect to PostgreSQL and list all databases:
psql -U devanshpc -l
This will show a list of databases. Look for the database you want to connect to, such as gradnet.

2. Connect to the Correct Database

If the database gradnet exists, specify it when connecting:
psql -U devanshpc -d grad

3. Create the Database (If Missing)

If gradnet does not exist in the list of databases, you need to create it:
  1. Connect to PostgreSQL's default postgres database:
    1. psql -U devanshpc -d postgres
  1. Create the gradnet database:
    1. CREATE DATABASE gradnet;
  1. Grant privileges to the user (if needed):
    1. GRANT ALL PRIVILEGES ON DATABASE gradnet TO devanshpc;
  1. Exit the psql prompt:
    1. \q

4. Connecting to the Database

After creating the gradnet database (if necessary), connect to it:
psql -U devanshpc -d gradnet