PostgreSQL server won't stop

后端 未结 8 530
醉话见心
醉话见心 2020-12-07 09:32

Having a bit of an issue with PostgreSQL on Mac OS X 10.8.4. I accidentally did brew rm postgresql --force while the postgres server was running. When I install

相关标签:
8条回答
  • $ brew services list

    $ brew services stop postgresql

    Stopping postgresql, but it might take a while → Successfully stopped postgresql (label: homebrew.mxcl.postgresql)

    0 讨论(0)
  • 2020-12-07 10:02

    I didn't have postgres started via brew services, so couldn't stop it that way.

    This worked.

    $ ps -ef | grep postgres
    501   547     1   0  2:07pm ??         0:00.29 /Applications/Postgres.app/Contents/Versions/9.6/bin/postgres -D /Users/username/Library/Application Support/Postgres/var-9.6 -p 5432
    

    Use -D paramater from above.

    $ pg_ctl stop -D "/Users/username/Library/Application Support/Postgres/var-9.6"
    
    0 讨论(0)
  • 2020-12-07 10:04

    I was having the same problem...removing the launch agent solved the problem for me:

    launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    
    0 讨论(0)
  • 2020-12-07 10:07

    I had a similar issue. I had forgot that I integrated 'lunchy' a few days ago and was using it as a launchctl wrapper to initiate plist ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist on start up. pg_ctl was not effective because of the following line of code <key>KeepAlive<key>:

          <?xml version="1.0" encoding="UTF-8"?>
         2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
         3 <plist version="1.0">
         4 <dict>
         5   <key>KeepAlive</key>
         6   <true/>
         7   <key>Label</key>
         8   <string>homebrew.mxcl.postgresql</string>
         9   <key>ProgramArguments</key>
        10   <array>
        11     <string>/usr/local/opt/postgresql/bin/postgres</string>
        12     <string>-D</string>
        13     <string>/usr/local/var/postgres</string>
        14     <string>-r</string>
        15     <string>/usr/local/var/postgres/server.log</string>
        16   </array>
        17   <key>RunAtLoad</key>
        18   <true/>
        19   <key>WorkingDirectory</key>
        20   <string>/usr/local</string>
        21   <key>StandardErrorPath</key>
        22   <string>/usr/local/var/postgres/server.log</string>
        23 </dict>
        24 </plist>
    

    Trying to kill the process directly didn't work because I needed to unload the plist.

        launchctl unload homebrew.mxcl.postgresql.plist
    
    0 讨论(0)
  • 2020-12-07 10:08

    Had same issue, pg_ctl: server does not shut down. Furthermore, ps auxwww | grep postgres showed no postgres running, while pg_ctl -D /usr/local/var/postgres status showed that postgres is running. Restarting my mac didn't help, i even went as far as to reset SMC, but this SO Q/A gave me an idea what to look for next: brew issues.

    Following this line of thought, i found this helpful blog post, that came down to following commands that solved this issue for me:

    $ brew services list
    $ brew services restart postgresql
    

    Hope this will help someone.

    Update - Unknown command: services

    After a bit of investigation following one of the comments ('Unknown command: services'), i found out that the authors of Homebrew decided to remove services from the repo, seeing as no one wants to maintain this code.

    You can read more about it here and here (related github tickets).

    After some more digging, I found this repo that adds services on macs.

    This is how I 'returned' services:

    ~ » brew tap gapple/services
    ~ » brew services
    usage: [sudo] brew services [--help] <command> [<formula>]
    
    Small wrapper around `launchctl` for supported formulae, commands available:
       cleanup Get rid of stale services and unused plists
       list    List all services managed by `brew services`
       restart Gracefully restart selected service
       start   Start selected service
       stop    Stop selected service
    
    Options, sudo and paths:
    
      sudo   When run as root, operates on /Library/LaunchDaemons (run at boot!)
      Run at boot:  /Library/LaunchDaemons
      Run at login: /Users/user/Library/LaunchAgents
    

    Here is another suggested solution: https://apple.stackexchange.com/questions/150300/need-help-using-homebrew-services-command. Didn't check it myself, so don't know if and how it works.

    0 讨论(0)
  • 2020-12-07 10:09

    I got round this error by using the command

    pg_ctl stop -m immediate
    
    pg_ctl start
    

    I did not need to unload the plist this way.

    0 讨论(0)
提交回复
热议问题