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

后端 未结 8 786
执笔经年
执笔经年 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:49

    Running pg_lsclusters will list all the postgres clusters running on your device eg:

    Ver Cluster Port Status Owner    Data directory               Log file
    9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
    

    if the status is down run

    #format is pg_ctlcluster <version> <cluster> <action>
    sudo pg_ctlcluster 9.6 main start
    

    If this process is not successfull it will throw the error. My error was(You can see the error log on /var/log/postgresql/postgresql-9.6-main.log)

    FATAL: could not access private key file "/etc/ssl/private/ssl-cert-snakeoil.key": Permission denied
    Try adding `postgres` user to the group `ssl-cert`
    

    make sure that postgres is the owner of /var/lib/postgresql/version_no/main eg: sudo chown postgres -R /var/lib/postgresql/9.6/main/

    It happened to me and it turned out that I removed erroneously the Postgres user from "ssl-cert" group. Run the below code to fix the user group issue and fixing the permissions

    #set user to group back with
    sudo gpasswd -a postgres ssl-cert
    
    # Fixed ownership and mode
    sudo chown root:ssl-cert  /etc/ssl/private/ssl-cert-snakeoil.key
    sudo chmod 740 /etc/ssl/private/ssl-cert-snakeoil.key
    
    # now postgresql starts! (and install command doesn't fail anymore)
    sudo service postgres restart
    
    0 讨论(0)
  • 2021-02-05 17:52

    That means your Postgres server is not running.

    Check Postgres Service status from Terminal

    sudo service postgresql status
    

    Enable Postgres Service, If not started

    sudo service postgresql start
    

    OR

    sudo service postgresql restart
    

    Now your command should work, If Postgres Service is successfully started.

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