Salon Appointment Scheduler - Build a Salon Appointment Scheduler- Unable to connect to postgres

Tell us what’s happening:
I’m getting the following error:

psql: error: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: FATAL: role “username=freecodecamp” does not exist

Describe your issue in detail here.
I’ve tried

  1. Reset
  2. closing my browser and restarting
  3. instructions on this thread : https://forum.freecodecamp.org/t/unable-to-connect-to-postgres/512012/2

!/bin/bash

PSQL=“psql -X username=freecodecamp --dbname=salon --tuples-only -c”

echo $($PSQL “TRUNCATE TABLE customers, appointments”)

echo -e “\n~~~~ MY SALON ~~~~\n”

display numbered list of services offerred

MENU(){

if [[ $1 ]]

then

echo -e “\n$1”

fi

get services available

AVAILABLE_SERVICES=$($PSQL “SELECT service_id, name FROM services ORDER BY service_id)”)

echo $AVAILABLE_SERVICES

print services available

echo -e “\nWelcome to My Salon, how can I help you? \n”

echo “$AVAILABLE_SERVICES” | while read SERVICE_ID BAR SERVICE_NAME

do

echo “$SERVICE_ID) $SERVICE_NAME”

done

read service selected

read SERVICE_ID_SELECTED

if service isn’t an integer, show the same list of services again

if [[ ! $SERVICE_ID_SELECTED =~ [1]+$ ]]

then

send to main menu

MENU “I could not find that service. What would you like today?”

fi

if the service doesn’t exist, show the same services again

SERVICE_ID=$($PSQL “SELECT service_id FROM services WHERE service_id = $SERVICE_ID_SELECTED”)

if [[ -z $SERVICE_ID ]]

then

MENU “I could not find that service. What would you like today?”

fi

prompt for phone number CUSTOMER_PHONE

echo -e “\nWhat’s your phone number.”

read CUSTOMER_PHONE

get customer name

CUSTOMER_NAME = echo $($PSQL “SELECT name FROM customers WHERE phone = ‘$CUSTOMER_PHONE’”)

if phone number does not exist get customer’s name CUSTOMER_NAME, enter name and phone number

into customers table

if [[ -z CUSTOMER_NAME ]]

then

echo -e “\nPlease enter your name.”

read CUSTOMER_NAME

echo $($PSQL “INSERT INTO customers(phone, name) VALUES(‘$CUSTOMER_PHONE’, ‘CUSTOMER_NAME’)”)

fi

prompt for time SERVICE_TIME

echo -e “\nPlease enter desired appointment time.”

read SERVICE_TIME

get customer ID

CUSTOMER_ID= $($PSQL “SELECT customer_id FROM customers WHERE phone =‘$CUSTOMER_PHONE’”)

insert row into appointments

echo $($PSQL “INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, $SERVICE_TIME)”)

get service name

SERVICE_NAME = $($PSQL “SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED”)

confirmation of appointment

echo “I have you put down for a $SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME”

}

MENU

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Salon Appointment Scheduler - Build a Salon Appointment Scheduler

Link to the challenge:

Thank you in advance.


  1. 0-9 ↩︎

TTT I’m still having issues with this anyone have any idea where to start to correct this issue?

Hey.
I think you may have forgotten the – before username in your PSQL variable.

try: PSQL=“psql -X --username=freecodecamp --dbname=salon --tuples-only -c”
instead of: PSQL=“psql -X username=freecodecamp --dbname=salon --tuples-only -c”

Hope it helps :slight_smile:

Thank you CalicoSquid for noticing. I’ve made the change but I’m still having problems connecting. Any other suggestions?

Blockquote PSQL=“psql -X --username=freecodecamp --dbname=salon --tuples-only -c”

Blockquotecodeally@806b1fca6bb8:~/project$ ./salon.sh
psql: error: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: No such file or directory
Is the server running locally and accepting connections on that socket?

Oh man, I’m seeing this error in my nightmares at the moment.
I am currently stuck with this after 99% completing the Student Database Part 2 (for the second time) and haven’t managed to figure it out. Literally 1 command from getting the check mark and Im about to delete my progress and start from scratch again…
Good luck, let me know if you find a solution somewhere.

Sorry for your troubles @carnegiebryson - you said you tried the instructions in the linked thread, I would give them one more try. Make sure you’re in the project folder when you run the commands.

Can you connect with the postgres user? psql -U postgres

Since this is one of the cert projects, you could save your files to your computer, delete your container, start the project again, and paste your files in the new container.