Skip to content

Instantly share code, notes, and snippets.

@taea
Last active January 12, 2023 14:22
Show Gist options
  • Save taea/8865831 to your computer and use it in GitHub Desktop.
Save taea/8865831 to your computer and use it in GitHub Desktop.
postgres をちゃんと終了しないと.pidファイルが残っちゃって、Rails が起動しないもんだい

Rails 起動しようとするとこんなエラーでる

PG::ConnectionBad at /
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?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?

かくにん

$ ps aux | grep postgres

ナニもウゴイてない( ˘ω˘)

taea            1489  0.0  0.0  2432768    616 s001  R+  12:57AM  0:00.00 grep postgres

かくにん

$ tail /usr/local/var/postgres/server.log

なんかある

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 189) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 189) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 189) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 189) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 189) running in data directory "/usr/local/var/postgres"?

順番に

rm /usr/local/var/postgres/postmaster.pid
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
ps aux | grep postgres

普通にウゴイタっぽい( ˘ω˘)

taea            1574  0.0  0.0  2432768    612 s001  R+  12:58AM  0:00.00 grep postgres
taea            1567  0.0  0.0  2439184    460  ??  Ss  12:58AM  0:00.00 postgres: stats collector process      
taea            1566  0.0  0.0  2583632  1632  ??  Ss  12:58AM  0:00.00 postgres: autovacuum launcher process      
taea            1565  0.0  0.0  2583500    624  ??  Ss  12:58AM  0:00.00 postgres: wal writer process      
taea            1564  0.0  0.0  2583500    672  ??  Ss  12:58AM  0:00.00 postgres: writer process      
taea            1563  0.0  0.0  2583500    668  ??  Ss  12:58AM  0:00.00 postgres: checkpointer process      
taea            1555  0.0  0.1  2583500  13096  ??  S    12:58AM  0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log

postgres がちゃんと正常に終了しないと、.pid ファイルって言うプロセスの ID を書いておくファイルが残っちゃうみたいです なので、.pid ファイルを消して、もう一回起動し直したのでした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment