PostgreSQL error 'Could not connect to server: No such file or directory'

前端 未结 22 1894
梦谈多话
梦谈多话 2020-11-29 17:20

Like some others I am getting this error when I run rake db:migrate in my project or even try most database tasks for my Ruby on Rails 3.2 applications.

22条回答
  •  温柔的废话
    2020-11-29 18:01

    When you run: psql -p 5432 -h localhost it does not use the loopback driver but uses a real socket and hence you need to configure postgres to accept socket connections. Hence even though pgadmin and other clients may work, psql will not.

    You need to change both the postgresql.conf file and the pg_hba.conf files so allow connection over a real socket. This will also allow connection from a remote ip which is why it is disabled by default.

    These files are in the data directory but the actual location can be different depending on how postgres was installed. With postgres running, run the command:

    ps -ef | grep postmaster
    

    These two files are the -D directory (maybe /usr/local/pgsql/data).

    For the postgresql.conf file, uncomment the listen_address and change it to be:

    listen_address = '*'
    

    For the pg_hba.conf add the line:

    host all all 0.0.0.0/0 md5
    

提交回复
热议问题