Unable to connect to postgres

Hi, I’m building the appointment scheduler and for a few days now I’ve been getting this message when I try to connect to psql:
codeally@c57ab2b73578:~/project$ psql --username=freecodecamp dbname=postgres
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?
In the other terminal I get some equivalent message when trying to run my bash script.
Is this a problem with codeally or is it something I can fix on my machine?
Thanks a lot!
Fco

Oh, is this what the learn outage announcement is all about? In that case, I’m sorry for asking…

It might be related to one of the outages, freeCodeCamp and CodeAlly both had some issues recently - as well as updates.

Enter these commands in the terminal:

  1. sudo cp ./.freeCodeCamp/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
  2. sudo chown -R postgres:postgres /var/lib/postgresql/12/main
  3. sudo service postgresql restart
  4. echo "SELECT 'CREATE USER freecodecamp WITH CREATEDB' WHERE NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname='freecodecamp')\gexec" | psql -U postgres -X

They’re the commands that run when you start that project to set things up. Try to login again after that. Let me know if it works.

1 Like

Yes, worked.
Thanks a lot!

1 Like

I am getting this error in the third command, help please!

Error: /usr/lib/postgresql/12/bin/pg_ctl /usr/lib/postgresql/12/bin/pg_ctl start -D /var/lib/postgresql/12/main -l /var/log/postgresql/postgresql-12-main.log -s -o  -c config_file="/etc/postgresql/12/main/postgresql.conf"  exited with status 1: 
pg_ctl: another server might be running; trying to start server anyway
 FATAL:  could not remove old lock file "postmaster.pid": Read-only file system
 HINT:  The file seems accidentally left over, but it could not be removed. Please remove the file by hand and try again.
pg_ctl: could not start server
Examine the log output.

In my case sudo service postgresql restart did not work. I got pg_ctl: could not start server

codeally@c04db3918a02:~/project$ sudo service postgresql restart
 * Restarting PostgreSQL 12 database server                                                                                                           * Error: /usr/lib/postgresql/12/bin/pg_ctl /usr/lib/postgresql/12/bin/pg_ctl start -D /var/lib/postgresql/12/main -l /var/log/postgresql/postgresql-12-main.log -s -o  -c config_file="/etc/postgresql/12/main/postgresql.conf"  exited with status 1: 
2022-09-14 14:35:39.122 UTC [3495] LOG:  starting PostgreSQL 12.9 (Ubuntu 12.9-2.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
2022-09-14 14:35:39.122 UTC [3495] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2022-09-14 14:35:39.122 UTC [3495] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
2022-09-14 14:35:39.122 UTC [3495] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-09-14 14:35:39.130 UTC [3495] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-09-14 14:35:39.155 UTC [3496] LOG:  database system shutdown was interrupted; last known up at 2022-09-14 14:32:27 UTC
2022-09-14 14:35:39.199 UTC [3496] LOG:  database system was not properly shut down; automatic recovery in progress
2022-09-14 14:35:39.204 UTC [3496] LOG:  redo starts at 0/1829EB8
2022-09-14 14:35:39.204 UTC [3496] LOG:  invalid record length at 0/182A288: wanted 24, got 0
2022-09-14 14:35:39.204 UTC [3496] LOG:  redo done at 0/182A210
2022-09-14 14:35:39.231 UTC [3496] PANIC:  could not fdatasync file "000000010000000000000001": Input/output error
2022-09-14 14:35:39.337 UTC [3495] LOG:  startup process (PID 3496) was terminated by signal 6: Aborted
2022-09-14 14:35:39.337 UTC [3495] LOG:  aborting startup due to startup process failure
2022-09-14 14:35:39.338 UTC [3495] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.

Then I had also to run sudo chmod 644 /etc/postgresql/12/main/pg_hba.conf

Source error:

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?