【问题标题】:Cannot kill Postgres process无法杀死 Postgres 进程
【发布时间】:2017-06-17 17:26:48
【问题描述】:

我一直试图杀死在端口 5432 上运行的 PostgreSQL 进程,但无济于事。每当我输入sudo lsof -i :5432 时,我都会看到如下内容:

COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
postgres 587 postgres    4u  IPv6 0x218f97e9af5d0303      0t0  TCP *:postgresql (LISTEN)
postgres 587 postgres    5u  IPv4 0x218f97e9ae0f6c63      0t0  TCP *:postgresql (LISTEN)

然后我尝试使用sudo kill -9 587 终止本例中的进程587,但随后另一个进程在同一端口上自动重新启动!我也尝试在活动监视器上杀死它,但无济于事。请帮忙?

谢谢, 劳拉

【问题讨论】:

  • 不要在主 PostgreSQL 进程(postmaster)上使用kill -9。存在一些 PostgreSQL 后端进程不会立即死亡的危险,如果在所有旧进程消失之前启动新的 postmaster,您将最终导致数据损坏。
  • 劳伦兹是对的。从命令行杀死 Postgres 进程是个坏主意。您需要正确关闭 Postgres(例如 pg_ctl stop
  • 我有同样的问题,首先我试图用 pg_terminate_backend 杀死一个用户,没有结果,然后我执行 pg_ctl stop -mf,但没有结果,就在我杀死特定会话时with kill -9 死了,但我的服务器重新启动

标签: macos postgresql


【解决方案1】:

如果你使用 brew 安装了 postgres,这个命令可能就是你要找的:

brew services stop postgres

【讨论】:

    【解决方案2】:

    我安装了 9.5 和 9.6,所以

    sudo su - postgres

    /Library/PostgreSQL/9.6/bin/pg_ctl -D /Library/PostgreSQL/9.6/data stop

    9.5 开始...

    /Library/PostgreSQL/9.5/bin/pg_ctl -D /Library/PostgreSQL/9.5/data stop

    【讨论】:

      【解决方案3】:

      列出你的 postgres pid:

      pg_ctl status -D /usr/local/var/postgres
      pg_ctl: server is running (PID: 715)
      

      强行杀死它..

      kill -9 715
      

      【讨论】:

        【解决方案4】:

        尝试运行这个命令:

        sudo pkill -u postgres
        

        【讨论】:

          【解决方案5】:

          该进程可能正在重新启动,因为它是从 launchd 守护进程生成的。您可以尝试通过launchctl 命令找到并杀死它:

          $ launchctl list
          

          要杀死一个进程,你会:

          $ launchctl kill
          

          【讨论】:

          • 我发现了一些与 Postgres 相关的进程,但是如何杀死它们呢?我试过launchctl kill 5660com.postgresapp.Postgres2MenuHelper.1184,但语法不正确:/
          • 您还必须使用信号名称或编号...所以launchctl kill 9 ... 如果进程再次产生,您也可以尝试launchctl disable ...launchctl unload。在终端尝试做 man launchctl 寻求帮助。
          【解决方案6】:

          我在尝试停止 postgres 时遇到了这个问题。我无法使用pg_ctl stop。我使用 brew 安装了 postgress。

          我最终偶然发现了this post,它为我解决了这个问题。

          【讨论】:

            猜你喜欢
            • 2013-08-05
            • 2015-06-08
            • 2015-06-01
            • 2016-07-13
            • 1970-01-01
            • 2015-01-06
            • 2018-05-07
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多