postgresql 致命错误锁定文件“postmaster.pid”已存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36436120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:13:05  来源:igfitidea点击:

FATAL ERROR lock file "postmaster.pid" already exists

postgresqlpostgis

提问by skwidbreth

I have recently installed PostGIS on my Mac (El Capitan 10.11.4, Postgres is version 9.5.1) using Homebrew, and I am following these instructions - http://morphocode.com/how-to-install-postgis-on-mac-os-x/

我最近使用 Homebrew 在我的 Mac(El Capitan 10.11.4,Postgres 是 9.5.1 版)上安装了 PostGIS,我正在遵循这些说明 - http://morphocode.com/how-to-install-postgis-on- mac-os-x/

When I try to start Postgres using

当我尝试使用

pg_ctl -D /usr/local/var/postgres start 

I get the following error:

我收到以下错误:

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

So I spent a few hours researching how to address this, but to no avail.

所以我花了几个小时研究如何解决这个问题,但无济于事。

Notably, I tried to kill the PID as recommended in an answer on Superuser - https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists-(in the case above, I ran kill 208), but as soon as I tried to start Postgres again, I got the same error, albeit with a different PID number. I saw a few people recommended deleting the postmaster.pid file, but I feel like maybe I should save that as a last resort...

值得注意的是,我试图按照超级用户的答案中的建议终止 PID - https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists-(在上述情况下,我跑了kill 208),但是当我再次尝试启动 Postgres 时,我遇到了同样的错误,尽管 PID 号不同。我看到一些人建议删除 postmaster.pid 文件,但我觉得也许我应该将其保存为最后的手段......

Admittedly part of the reason I'm not sure how to fix this is that I'm not really clear on what the postmaster even is - I'm just starting to learn about all of this.

不可否认,我不确定如何解决这个问题的部分原因是我不太清楚邮政局长到底是什么——我刚刚开始了解所有这些。

Hopping into a Postgres database via the psql db_namecommand works just fine, for what it's worth.

通过psql db_name命令跳转到 Postgres 数据库工作得很好,这是值得的。

采纳答案by Jakub Kania

Postmasteris the main PostgreSQL process. You're trying to start PostgreSQL that's already running (and you're saying yourself you can connect to it). Just skip that step of your process.

Postmaster是主要的 PostgreSQL 进程。您正在尝试启动已经在运行的 PostgreSQL(并且您说自己可以连接到它)。只需跳过流程的那一步。

回答by ludditedev

Posting this in case it helps someone else:

发布此信息以防对其他人有帮助:

I was having this same problem as the OP after a hard reboot when my laptop crashed. What helped me was running the following command to see what PID was associated with postmaster.pid:

当我的笔记本电脑崩溃时,在硬重启后,我遇到了与 OP 相同的问题。帮助我的是运行以下命令来查看与 postmaster.pid 关联的 PID:

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

The first number that appears will be the PID. Looking in Activity Monitor, I was able to see that Postgres was running, but without a PID number that matched the one shown.

出现的第一个数字将是 PID。查看活动监视器,我能够看到 Postgres 正在运行,但没有与显示的 PID 号匹配的 PID 号。

Instead of the steps outlined in the answer referenced on Superuser, I restarted my laptop properly and then opened up Terminal and ran

我没有按照 Superuser 上引用的答案中概述的步骤,而是正确地重新启动了我的笔记本电脑,然后打开终端并运行

brew services restart postgresql

This worked without having to remove postmaster.pid, which I saw a few other posts recommend. Sometimes it's the simple solutions that work.

这无需删除 postmaster.pid 即可工作,我看到了其他一些帖子推荐。有时它是有效的简单解决方案。

回答by Kamil Gosciminski

Since you can connect to the database, you don't need to start the server again - it's already running.

由于您可以连接到数据库,您不需要再次启动服务器 - 它已经在运行。



pg_ctlis used to control the PostgreSQL server. Since your server is already started, your command:

pg_ctl用于控制 PostgreSQL 服务器。由于您的服务器已经启动,您的命令:

pg_ctl -D /usr/local/var/postgres start

Returns an error, saying that there is a lock on postmaster.pid- which is true since there is already a server running under that PID.

返回一个错误,说有一个锁定postmaster.pid- 这是真的,因为已经有一个服务器在该 PID 下运行。



There are two ways:

有两种方式:

  1. The most basic way - skip that step, your server is already running!
  2. Executing a needless operation - stopping the server, and then starting it again.
  1. 最基本的方法——跳过这一步,你的服务器已经在运行了
  2. 执行不必要的操作 - 停止服务器,然后再次启动它。

You could stop your server doing :

你可以停止你的服务器做:

pg_ctl -D /usr/local/var/postgres stop

So that you won't have the lock on postmaster anymore and you could use your command to start it again.

这样您就不会再锁定 postmaster 并且您可以使用您的命令重新启动它。

回答by Sobin Sunny

It often happens to me in OSx, when my system shutdown unexpectedly.

当我的系统意外关闭时,在 OSx 中经常发生这种情况。

You can just remove the file postmaster.pid.

您可以删除该文件postmaster.pid

cd Library/Application Support/Postgres/var-{postgres-version}

and remove the postmaster.pid file

并删除 postmaster.pid 文件

restart the Postgres by using this command

使用此命令重新启动 Postgres

pg_ctl -D /usr/local/var/postgres restart

回答by remnant

My OSX laptop had shutdown unexpectedly, and I was getting a stale postmaster.pid error in the PostgresApp. Shutting down my laptop and turning it back on again solved the problem.

我的 OSX 笔记本电脑意外关机,并且我在 PostgresApp 中收到过时的 postmaster.pid 错误。关闭我的笔记本电脑并再次打开它解决了这个问题。

回答by Abdul

If you have installed postgres with brew then simply run the following command and it will manage everything

如果你已经用 brew 安装了 postgres,那么只需运行以下命令,它就会管理一切

 brew services restart postgresql