error with postgresql datababse : Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

后端 未结 8 802
执笔经年
执笔经年 2021-02-05 17:09

When I run the rake db:migrate or run the rails s command, I get the same error:

Error : could not connect to server: 
No such file or         


        
相关标签:
8条回答
  • 2021-02-05 17:28

    The exact same symptom can be caused by a stale lock file /var/run/postgresql/.s.PGSQL.5432.lock. One of the symptoms of this is psql reporting

    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"?

    even though there is clearly a socket with this path available as reported by netstat -lp --protocol=unix | grep postgres

    The problem can be solved by removing the lock file and restarting postgresql. This is definitely less invasive than a purge and re-install.

    sudo rm /var/run/postgresql/.s.PGSQL.5432.lock
    sudo service postgresql restart
    
    0 讨论(0)
  • 2021-02-05 17:40

    Solution:

    Try this

    export LC_ALL="en_US.UTF-8"
    

    and this. (9.3 is my current PostgreSQL version. Write your version!)

    sudo pg_createcluster 9.3 main --start
    
    0 讨论(0)
  • 2021-02-05 17:41

    When I run into this error, my Postgres server was actually listening on a different port (5433) and not 5432. To solve this, add

    port: 5433
    

    to your database.yml file to instruct rails to use the same

    0 讨论(0)
  • 2021-02-05 17:45

    I had the same Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”? error when typing psql into the postgres user in Ubuntu 14.04. I could not find an existing working solution.

    The short answer for me was: my install made a var/pgsql_socket directory but no configuration files knew about it.

    1) Find the postgres.conf file (it was in etc/postgresql/9.6/main for me)
    2) change to listen_addresses = '*'
    3) add another unix socket directory
    unix_socket_directories = '/var/run/postgresql, /var/pgsql_socket' # comma-separated list of directories
    4) at this point, sudo service postgresql start attempted to start but did not have authority to create the lock file.
    * The PostgreSQL server failed to start. Please check the log output: 2016-10-05 17:14:55 CEST [28472-1] FATAL: could not create lock file "/var/pgsql_socket/.s.PGSQL.5432.lock": Permission denied 2016-10-05 17:14:55 CEST [28472-2] LOG: database system is shut down
    5) Change permissions ( found from Mark Berry's comment here )
    $ sudo chown root.postgres /var/pgsql_socket
    $ sudo chmod g+wx /var/pgsql_socket
    6) sudo service postgresql start
    sudo -i -u postgres
    psql

    That finally worked for me

    0 讨论(0)
  • 2021-02-05 17:48

    The convention for PostgreSQL packaged for Debian or Debian derivatives such as Ubuntu is to use /var/run/postgresql as the directory for Unix domain sockets. On the other hand the convention for self-compiled postgres client libs is to use /tmp, unless self-configured otherwise.

    So the usual root cause of this mismatch between both is a mix of self-compiled client-side stuff with pre-compiled server-side packages (even if client and server are installed on the same machine, client-side and server-side are still distinct and can be out of sync).

    Soft-linking from /tmp to this directory as suggested by the asker works except that the link will be lost at every reboot, because in general /tmp is emptied on reboot.

    A better option would be to add as an entry in database.yml:

    • either host: /tmp if the real socket path is /tmp (self-compiled server, packaged client)

    • or host: /var/run/postgresql if the real socket path /var/run/postgresql/ (packaged server, self-compiled client).

    When the value in the host field starts with a slash character, the postgres library knows that it's the location of a directory for local sockets rather than a hostname. The filename inside the directory .s.PGSQL.portnumber is generated and must not be specified, only the directory.

    Another possibility is to configure the self-compiled software packages as closely as possible to Debian, overriding the defaults as they do.

    0 讨论(0)
  • 2021-02-05 17:49

    I solved It . I Just created a softlink using :

    sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432

    and then edited the

    /etc/postgresql/9.4/main/pg_hba.conf

    ( If you have another version of postgresql you have to change 9.4 in the path)

    From:

    local all postgres peer

    To:

    local all postgres md5

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