Postgres DB 没有在 Mac 上启动: 错误提示: 连接在 Unix domain socket 上

我已经安装了 Postgreql,然后在我的本地 Mac OSX Mountain Lion 上运行了一些 Rails 应用程序,并创建了数据库等等。今天,当我启动 pgAdminIII 并试图启动一个数据库服务器时,我得到了这个错误:

enter image description here

一个快速谷歌显示 这个职位。更多的浏览指出了这样一个事实,即可能存在某种 postmaster. pid 文件,这可能是造成这种情况的根本原因。如果我删掉那些东西,一切都会好起来的。

然而,在我去删除我的计算机上的东西,我想确保我调试这在一个系统的方式,不会导致更多的问题。

在删除该文件之前,我在某个地方读到了这个命令,我需要运行以下命令:

  ps auxw | grep post

如果没有结果,可以删除文件。否则不行。我得到的结果是:

  AM               476   0.0  0.0  2423356    184 s000  R+    9:28pm   0:00.00 grep post

所以现在我完全糊涂了。

那我该怎么办?

下面是我的 postgres 服务器错误日志的一部分:

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

Postgreql 仍然没有运行,仍然得到相同的错误,没有任何改变。我太胆小了,没有检查所以不能删除东西。

你们这些专家能不能指导一下菜鸟。

谢谢

60776 次浏览

I have the database working now.

Here are the steps I took:

  1. I rebooted my computer
  2. I opened the terminal and ran cd /
  3. Then I did ls -la
  4. Ensured that I could get to MackintoshHD/usr/local/var/postgres
  5. Then did ls -la
  6. Here I saw the postmaster.pid file
  7. I ran this command cp postmaster.pid ~/Desktop which copied the file to my desktop.I like to do this if I am deleting files. If something does wrong i can put it back
  8. Then I ran this command to remove the file from the postgres directory rm -r postmaster.pid
  9. I went to my pgadmin3 gui and fired it up. and Voila it worked :)

Thanks to @Craig Ringer for his help

This can happen if the database did not shut down correctly. To fix it simply delete the postmaster.pid file. The location differs based on your OS:

MacOS:

 rm /Users/<user_name>/Library/Application\ Support/Postgres/var-9.6/postmaster.pid

or using Postgres.app:

 rm /Users/<user>/Library/Application\ Support/Postgres/var-10/postmaster.pid

Linux:

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

I had the same problem today on Mac Sierra. In Mac Sierra you can find postmaster.pid inside /Users/<user_name>/Library/Application Support/Postgres/var-9.6. Delete postmaster.pid and problem will be fixed.

I'm using Postgres.app, and the below worked for me:

I entered the commands into my terminal below, locating the Postgres folder beforehand and not using "justin".

$declare -x PGDATA="/Users/justin/Library/Application Support/Postgres/var-9.4"


$pg_ctl restart -m immediate

As Justin explains in his post, the output after this was:

waiting for server to shut down……………………………………………………… failed pg_ctl: server does not shut down

After entering the command again:

$pg_ctl restart -m immediate

It worked and I got this message:

pg_ctl: old server process (PID: 373) seems to be gone starting server anyway server starting LOG: database system was interrupted; last known up at 2015-07-28 18:15:26 PDT LOG: database system was not properly shut down; automatic recovery in progress LOG: record with zero length at 0/4F0F7A8 LOG: redo is not required LOG: database system is ready to accept connections LOG: autovacuum launcher started

Source