无法连接到服务器:“/var/run/postgresql/.s.PGSQL.5432”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22762635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:23:09  来源:igfitidea点击:

could not connect to server: "/var/run/postgresql/.s.PGSQL.5432"?

ruby-on-railsrubypostgresqlheroku

提问by mayrues

I have a simple web page in Ruby On Rails with postgresql database, but when I run sever I have this error, I don't Know that I do. I use postgresql because heroku need that the aplication is in postgresql.

我在带有 postgresql 数据库的 Ruby On Rails 中有一个简单的网页,但是当我运行 sever 时出现此错误,我不知道我这样做了。我使用 postgresql 是因为 heroku 需要应用程序在 postgresql 中。

I work in ubuntu 13.10

我在 ubuntu 13.10 工作

The error is:

错误是:

PG::ConnectionBad 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"?

PG::ConnectionBad 无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?

I need help

我需要帮助

thanks

谢谢

回答by ramamoorthy_villi

Just create a softlink like this,this works for me

只需创建一个这样的软链接,这对我有用

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

for more info

了解更多信息

回答by Sergey Bezugliy

Also you are able to force stop and then force start the server

您也可以强制停止然后强制启动服务器

sudo service postgresql stop --force

sudo service postgresql start --force

sudo service postgresql stop --force

sudo service postgresql start --force

回答by ToTenMilan

I had this error due to not properly configured connection to database, and exactly because of syntax errors in setting up environment variables i.e.

由于没有正确配置到数据库的连接,并且完全因为设置环境变量时的语法错误,我遇到了这个错误,即

MY_APP_DB= $MY_APP_DB_NAMEwhich is wrong, instead of MY_APP_DB=$MY_APP_DB_NAME

MY_APP_DB= $MY_APP_DB_NAME这是错误的,而不是 MY_APP_DB=$MY_APP_DB_NAME

回答by Sanjay Choudhary

sudo systemctl start postgresql

回答by illusionist

First, you need to make sure the socket fileis located in /var/run/postgresql/.s.PGSQL.5432. To check that

首先,您需要确保socket file位于/var/run/postgresql/.s.PGSQL.5432. 要检查

$ cat /var/run/postgresql/.s.PGSQL.5432

if result shows something, then the problem is anything else. But, if file is not there you need to check /tmpdir (specially for OSX Homebrewusers)

如果结果显示某些内容,则问题是其他任何问题。但是,如果文件不存在,您需要检查/tmp目录(特别是对于 OSXHomebrew用户)

$ cd /tmp
$ l

total 16
drwxrwxrwt  7 root   wheel   224B Mar 11 08:03 .
drwxr-xr-x  6 root   wheel   192B Jan 23 18:35 ..
-rw-r--r--  1 root   wheel    65B Nov  7 22:59 .BBE72B41371180178E084EEAF106AED4F350939DB95D3516864A1CC62E7AE82F
srwxrwxrwx  1 shiva  wheel     0B Mar 11 08:03 .s.PGSQL.5432
-rw-------  1 shiva  wheel    57B Mar 11 08:03 .s.PGSQL.5432.lock
drwx------  3 shiva  wheel    96B Mar 10 17:11 com.apple.launchd.C1tUB2MvF8
drwxr-xr-x  2 root   wheel    64B Mar 10 17:10 powerlog

Now, there are two ways you can solve the error

现在,有两种方法可以解决错误

Solution One

解决方案一

You can change the application configuration to see for sockets at /tmp/.s.PGSQL.5432

您可以更改应用程序配置以查看套接字 /tmp/.s.PGSQL.5432

For Rails Users

对于 Rails 用户

# config/database.yml

default: &default
  adapter: postgresql
  pool: 5
  # port: 
  timeout: 5000
  encoding: utf8
  # min_messages: warning
  socket: /tmp/.s.PGSQL.5432

Solution Two

方案二

You can create symlinks to the expected location

您可以创建指向预期位置的符号链接

$ sudo mkdir /var/pgsql_socket
$ sudo ln /tmp/.s.PGSQL.5432 /var/pgsql_socket/

Then the error should go.

然后错误应该消失。

Hope this helps.

希望这可以帮助。

回答by apeironsv22

What you have to do to solve the problem of s.PGSQL.5432:

解决s.PGSQL.5432的问题你需要做什么:

First change the unix_socket_directories postgresql.conf path / tmp / by another route

首先将unix_socket_directories postgresql.conf路径/tmp/改成另外一条路径

and then updates the postgres and postgres load becomes, if you want you can put the path again, and with it and recharge the postgres normally.

然后更新postgres和postgres负载,如果你愿意,你可以再次放置路径,并用它正常为postgres充电。