[RUBY] When I did rails new, I got an error saying PG :: ConnectionBad: could not connect to server: No such file or directory

It looks like the error "PostgreSQL is not running". It seems that it was due to the restart of the PC, but it was solved by the following method. Although I have encountered it many times, I felt that I was checking the recovery procedure every time, so I will record it.

procedure

① Go to the front of the log file output by PostgreSQL

$ cd /usr/local/var/log

② Check the contents of the file

$ cat postgres.log

↓↓↓ スクリーンショット 2020-12-27 16.19.25.png

lock file "postmaster.pid"Many were displayed as already exists.



#### **`postmaster.I heard that the pid file already exists, so I deleted it.`**
```I heard that the pid file already exists, so I deleted it.



 ④ Delete the file with the rm command

$ rm /usr/local/var/postgres/postmaster.pid


 After the deletion, I was able to execute rails new safely.

## result
 postmaster.pid is a mechanism to prevent multiple servers from being started, and it seems that it is created when the server is started and deleted when it is stopped.
 If the server is not stopped normally, files may remain, which leads to an error like this one.



Recommended Posts

When I did rails new, I got an error saying PG :: ConnectionBad: could not connect to server: No such file or directory
PG :: ConnectionBad: could not connect to server: No such file or directory
[Docker] When I did docker-compose build, I got an error saying Can not read file. .. [Rails 6.0]
No such file or directory @ rb_sysopen-/Users/○○/Gemfile.lock (Errno :: ENOENT) suffered
PG :: ConnectionBad: could not connect to server: No such file or directory
When dealing with whenever in Docker No such file or directory --crontab
When I did rails new, I got an error saying PG :: ConnectionBad: could not connect to server: No such file or directory
[Android] no such table error solution
Error: Error response from daemon: No such container:
[Error] `cannot load such file --mime/types/data (LoadError)`
Attempting to run gnome-terminal inside a Docker container fails (Failed to execute child process “dbus-launch” (No such file or directory))
In WSL2, when I did `docker-compose up`, I got an error saying that the sh file was not found.
[PostgreSQL] could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
When dealing with whenever in Docker No such file or directory --crontab
When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.
I got an error when I ran rake routes.
I got an error when trying to install sbt to build a Scala development environment