postgresql psql : could not connect to server: No such file or directory

16,550

PostgreSQL-9.6.5 for Ubuntu 16.04 via the installer (but this may be redundant)

This isn't redundant, you've installed two different versions of Postgres in two different locations. On a package management system like Ubuntu (and most flavors of Linux) you should only use the version of software found int he package manager. You likely used the installer off their website which installed Postgres either in /opt/ or /usr/local/ and changed your systemd target files to point to that installation. Meanwhile your client comes from the package manager and is expecting the UNIX domain socket it connects to in /var/run.

If this is a throw away virtual machine, wipe it, reinstall and only install Postgres via apt-get. If not, see if you can uninstall the package you downloaded and reinstall the other packages via apt-get (which will hopefully fix your systemd target files to point to the right location).

Share:
16,550

Related videos on Youtube

Max
Author by

Max

Updated on September 18, 2022

Comments

  • Max
    Max over 1 year

    First I want to start by saying the most relevant answer was here. When I try to run the following here's what I get:

    $ sudo -u postgres psql
    psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
    

    I can also confirm that the server starts up and quits by running the first command below. The second command below confirms that the server started but immediately exited,

    $ sudo service postgresql restart
    $ sudo service postgresql status
    ● postgresql.service - PostgreSQL RDBMS
       Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
       Active: active (exited) since Mon 2017-09-25 18:37:32 EDT; 11min ago
      Process: 8459 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
     Main PID: 8459 (code=exited, status=0/SUCCESS)
    
    Sep 25 18:37:32 atas-250-557 systemd[1]: Starting PostgreSQL RDBMS...
    Sep 25 18:37:32 atas-250-557 systemd[1]: Started PostgreSQL RDBMS.
    

    An answer that seems promising:

    • postgresql.org telling me to start my server in /usr/local/pgsql/data but I DON'T EVEN HAVE the dir /usr/local/pgsql. This leads me to believe that in my installations and deletions something was not reinstalled.

    • I have installed

      • sudo apt-get install postgresql
      • sudo apt-get install postgresql-client-common
      • sudo apt-get install postgresql-client
      • PostgreSQL-9.6.5 for Ubuntu 16.04 via the installer (but this may be redundant).

    Lastly, the uninstaller found in /opt/PostgreSQL/9.6 doesn't even remove everything from my system the way it should. I'm left with a the window of the leftover files after uninstalling. If you could help me fix the could not connect to server issue at the top that would be preferred. Last resort I would be willing to wipe everything clean, but haven't had any luck so far.

  • Max
    Max over 6 years
    Unfortunately it is not a virtual machine. I'll see what I can do to uninstall via the uninstaller