Common development issues part 1

Documenting them one at a time

Introduction

I usually face specific issues that always come up. I always find myself checking Google for the solution over and over.

I thought that checking on Google over and over was inefficient and to save me and probably others, some time, I will document some of the issues that I face.

For context, I happen to use an M1 Macbook for development.
You might wanna consider your specific situation.
Nevertheless, I hope this will be helpful.

Postgres stopping to work

I am not familiar with how this issue comes up.
My database of choice is usually Postgres.
But once in a while, when I am testing a Rails app on the development machine, I get this error;

connection to server on socket "/tmp/.s.PGSQL.5432" 
failed: No such file or directory 
Is the server running locally and accepting connections on that socket?

The solution to this issue

  1. Open the file /opt/homebrew/var/log/postgres.log to identify the problem. I used homebrew to install postgres so this it's location.

     27645 2023-06-22 11:54:14.111 EAT [21939] HINT:  Is another postmaster (PID 776) running in data directory "/opt/homebrew/var/postgres"?
     27646 2023-06-22 11:54:24.161 EAT [21946] FATAL:  lock file "postmaster.pid" already exists
     27647 2023-06-22 11:54:24.161 EAT [21946] HINT:  Is another postmaster (PID 776) running in data directory "/opt/homebrew/var/postgres"?
     27648 2023-06-22 11:54:34.206 EAT [21960] FATAL:  lock file "postmaster.pid" already exists
     27649 2023-06-22 11:54:34.206 EAT [21960] HINT:  Is another postmaster (PID 776) running in data directory "/opt/homebrew/var/postgres"?
     27650 2023-06-22 11:54:44.250 EAT [21975] FATAL:  lock file "postmaster.pid" already exists
    
  2. Sure enough, as indicated on lines 27648, and 2749 the error is clear.

  3. Deleting the postmater.pid file in the /opt/homebrew/var/postgres directory should solve this issue.

  4. Delete the postmaster.pid file using: rm -rf /opt/homebrew/var/postgres/postmaster.pid

  5. Restart postgres by running: brew services restart postgresql@14

  6. Now everything should work fine.

Conclusion

I hope that this is helpful.
Take the time to read and understand the problem.