PostgreSQL not running on Mac

  • The error in its entirety reads:

    psql: could not connect to server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

    This is my second time setting up Postgresql via Homebrew on my Mac, and I have no clue what is going on. Previously, it had been working. At some point, I must've entered a command that messed things up. I'm not sure. Now, whenever I enter a SQL command from the command line, I receive the above message. I've run a command to check whether the server is running, and it apparently is not. If I attempt to start the server using

    $ postgres -D /usr/local/pgsql/data

    I receive the following error:

    postgres cannot access the server configuration file "/usr/local/pgsql/data/postgresql.conf": No such file or directory

    I've uninstalled and reinstalled Postgresql via Homebrew, but the problem persists. I'm completely at a loss as to how to get this working. Any help would be appreciated.

  • Michael P.

    Michael P. Correct answer

    6 years ago

    The answer is here.

    Run this command to manually start the server:

    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
  • The problem can also be attributed to a crashed process that left file behind.

    $ brew services stop postgresql
    $ rm /usr/local/var/postgres/ # adjust path accordingly to your install
    $ brew services start postgresql

    On MacOSX, this answer saved me. Had the same error as OP after my computer hard rebooted. The `brew services` command were not helpful because they made it seem like everything was working. Removing the `` is what finally got everything working again. Thanks!

    This happened to me too. Hard crash of Mac OS X caused a restart, after that Postgres didn't come up. brew services start/stop/restart doesn't work, you have to manually remove the pid file.

    The recommended way would be to run Postgres in a docker container, of course. Very easy to start and everything is cleaned up when a container is shut down. I'd say running any third party app in a docker container should be de facto nowadays.

    Save my ass. Also caused after crash of macOS...

  • I was getting the same

    Is the server running locally and accepting connections on Unix domain 
    socket "/tmp/.s.PGSQL.5432"?

    loop of Homebrew install / start / stop / restart to no avail...

    Finally, brew postgresql-upgrade-database worked.

    Seems I was on 9.6 instead of 10.4, and something my latest App Store restart restarted all my database servers...

    this worked for me

    That `brew postgresql-upgrade-database` is what I was missing. Thanks for pointing that out.

    Worked for me thanks!

    I've tried all the solutions. But this is the only one worked for me. Would be great to know if anyone could explain why this fixed it completely.

    I dont know why this worked can some one explain me why?Thanks in advacne

    This worked for me. Thanks

    thanks save my time

  • I've just resolved the same problem. It's just because I forgot to run it properly before use.

    For pure installing postgresql on Mac OS, the process will be (using brew command):

    brew install postgresql

    then if you want to automatically run postgresql at login:

    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

    or else you just want to run it anytime you want:

    postgres -D /usr/local/var/postgres

    If your case is more complicated, let's brew uninstall postgresql and redo these steps.

    Hope it helps!

    Update: for Homebrew-installed postgres, `brew services start postgresql` is now the preferred way to start postgres at login

  • psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket"/var/pgsql_socket/.s.PGSQL.5432"?

    I kept on getting the above error and none of the above solutions worked for me. Finally the following solution solved my problem on Mac OS X

    Install postgres using brew

    brew install postgres

    Install brew services

    brew tap homebrew/services

    To start postgres as a background service

    brew services start postgresql

    To stop postgres manually

    brew services stop postgresql

    We can also use brew services to restart Postgres

    brew services restart postgresql
  • This happens when postgres server is not running. Steps to properly install Postgres via Homebrew on MAC :

    1. brew install postgres

    2. initdb /Users/<username>/db -E utf8 [This initializes postgres to use the given directory as the database directory. Normally it is not adviced to use the user directory for database storage. Edit sudoers file to add initdb and similar commands and then run initdb on /usr/local/var/postgres]

    3. pg_ctl -D /Users/<username>/db -l logfile start [After getting success with step 2 it will prompt to run step 3. This command manually starts the server.]

  • It worked for me. Change your postgresql directory according to version in your system.

    Common path- rm /usr/local/var/postgres/

    but for [email protected] in my system path is rm /usr/local/var/[email protected]/

    restart [email protected] brew services restart [email protected]

    yup thats the ONE that works!

  • recently I went thru a similar problem. there's just another problem and solution. I was running 2 version of postgres (9.3 and 9.6) although the server was set to run on 2 different port but some how the psql command on bash try to connect to default port 5432. Make sure to check if your server is running and check your port settings, then run psql -p <port> postgres. The solution is changing port.

  • I was looking for a long time, and this was the most clean and neat solution:

    I recently upgraded Postgres from 9.2 to 9.3 using brew upgrade postgres. The process was smooth and pg_upgrade is a very handy tool.

    However, trouble struck once I tried to run any specs that needed to connect to Postgres. Even though Postgres was definitely running, suddenly I was getting:

    could not connect to server: No such file or directory (PG::ConnectionBad) Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? The problem was that the new version of Postgres listens on /tmp/.s.PGSQL.5432 instead. I could’ve messed around with the config and made Postgres use the domain socket it was previously, or told Rails explictly how to connect, but both of those approaches seemed like work I shouldn’t have to do. At no point had I told Rails to connect to postgres on that path, Rails had assumed it, and now its assumptions were wrong.

    The fix is simple, if a little suprising. When you install the ‘pg’ gem, it detects which version of Postgres is installed and sets the domain socket path appropriately. The solution is as simple as reinstalling the gem. $ gem uninstall pg $ cd my-rails-app/ $ bundle install

    Please edit. You can find guidance on how to do this correctly in How to reference material written by others. Thank you.

  • For me this also happened after a reboot and none of the above solutions worked for me. After checking the server log like this:

    tail /usr/local/var/postgres/server.log

    I noticed:

        2019-11-06 11:04:31.797 CET [85029] FATAL:  data directory "/usr/local/var/postgres" has invalid permissions
    2019-11-06 11:04:31.797 CET [85029] DETAIL:  Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).

    So I changed the permissions like this:

    sudo chmod 700  /usr/local/var/postgres

    and everything worked again and life was good.

    Same, using [email protected] on osx 10.15. Last thing needed was a `brew services restart postgresql`

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM