Cannot connect to Postgres server through brew services

I searched for a solution for this and did not find a working solution.

I installed postgres using brew ( brew install postgres ) on my MacBook and I am currently running it using brew services (the brew services list displays postgres as a running service). However, when I try to start psql , I get the following error.

psql: cannot connect to server: no such file or directory. does the server work locally and accepts connections in the Unix socket domain "/tmp/.s.PGSQL.5432"?

Has anyone already solved a similar problem?

+40
homebrew postgresql macos
source share
8 answers

I had the same error, and I fixed it by deleting the process pid file:

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

+85
source share

I ran into this problem today. postgres stopped accepting connections, although the homegrown thought it was working.

To fix this I ran

 brew services restart -vvv postgresql 

Exiting this command

 ==> Successfully stopped 'postgresql' (label: homebrew.mxcl.postgresql) ==> Generated plist for postgresql: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.postgresql</string> <key>ProgramArguments</key> <array> <string>/usr/local/opt/postgresql/bin/postgres</string> <string>-D</string> <string>/usr/local/var/postgres</string> </array> <key>RunAtLoad</key> <true/> <key>WorkingDirectory</key> <string>/usr/local</string> <key>StandardErrorPath</key> <string>/usr/local/var/log/postgres.log</string> </dict> </plist> 

Then I thought, hmm, maybe there is something in this log file,

 tail -n 10 /usr/local/var/log/postgres.log 

Of course,

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

So, I deleted this file

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

And it all worked again.

+52
source share

In my case, the postmaster.pid file was not even there. I was able to get it working by updating postgres.

 brew update brew upgrade 

Then, since I upgraded the main version from 10 to 11, I also had to run this:

 brew postgresql-upgrade-database 

(source https://github.com/facebook/react-native/issues/18760#issuecomment-410533581 )

+14
source share

I would combine the two responses from Wilson and Grasshopper.

You can check the plist file for postgres with brew services list to find the location of the file and just open it in your favorite editor.

You should see a StandardErrorPath value indicated as:

 <key>StandardErrorPath</key> <string>/usr/local/var/log/postgres.log</string> 

And then you should close the end of the log file using tail -n 100 /usr/local/var/log/postgres.log

In my case, the error was as follows:

2017-12-06 11: 51: 16.078 GMT [85476] FATAL: the lock file "postmaster.pid" already exists 2017-12-06 11: 51: 16.078 GMT [85476] TIP: Is there another postmaster (PID 601) in the data directory "/ usr / local / var / postgres"?

This was due to the fact that I had to hard disable my Mac, and postgres did not get the opportunity to clear the PID file. Just delete the rm /usr/local/var/postgres/postmaster.pid PID file and run postgres brew services start postgresql

Warning word: do not delete this PID file if you are not sure that postgres is not working . You can do this by running brew services stop postgresql and then waiting for the result of the brew services list to show that posgres is in a stop state.

+11
source share

Deleting the /usr/local/var/postgres/ folder worked for me and then deleting and installing postgres again

+4
source share

I have the same error when installing postgresql93 from tap version. Checking the .plist file specified in the output of the brew services list ( ~/Library/LaunchAgents/homebrew.mxcl.postgresql93.plist ), I found the following message:

FATAL: the data directory "/ usr / local / var / postgres" has access to a group or world

DETAILS: Permissions must be u = rwx (0700).

What led me to this answer: the data directory "/ usr / local / var / postgres" has the wrong ownership

After running sudo chmod -R 700 /usr/local/var/postgres , I got another error:

FATAL: could not open the directory "pg_tblspc": no such file or directory

Which led me to: `pg_tblspc`, missing after installing the latest version of OS X (Yosemite or El Capitan)

After starting mkdir /usr/local/var/postgres/pg_tblspc/ cluster started successfully.

+3
source share

I started brew postgres , but only with yellow . I use this article to solve the problem:

https://engineering.kapost.com/2018/12/brew-services-postgres-suddenly-wont-start

And now it works.

Thanks @ Aaron Snyder

0
source share

update it with the command

  brew postgresql-upgrade-database 

if you have the following error The 'brew' command was not found , but it can be installed using: sudo apt install linuxbrew-wrapper

then install it with the command

  sudo apt install linuxbrew-wrapper 
0
source share

All Articles