[RUBY] Postgres error "PG :: ConnectionBad"

I stumbled on it many times, so I made a brief note

PG::ConnectionBad

could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

スクリーンショット 2020-09-10 22.17.38.png

% postgres -D /usr/local/var/postgres
2020-09-10 22:13:34.167 JST [8631] FATAL:  lock file "postmaster.pid" already exists
2020-09-10 22:13:34.167 JST [8631] HINT:  Is another postmaster (PID 494) running in data directory "/usr/local/var/postgres"?
% rm /usr/local/var/postgres/postmaster.pid

Delete postmaster.pid with rm

% brew services restart postgresql

I'll restart you.

% rails s

Start and check

point

postmaster.pid remains If postgresql is not finished normally The result of leaving a file called postmaster.pid It seems that an error that cannot be started occurs.

I will investigate it in a little more detail and update it again. It seems necessary to have a mechanism for starting and stopping postgresql Until the memo this time.

Reference article

https://qiita.com/great084/items/98c83364f246473249c4

Recommended Posts

Postgres error "PG :: ConnectionBad"