postgresql 套接字文件“/var/pgsql_socket/.s.PGSQL.5432”在 Mountain Lion (OS X Server) 中丢失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13868730/
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-09-10 23:54:22  来源:igfitidea点击:

Socket File "/var/pgsql_socket/.s.PGSQL.5432" Missing In Mountain Lion (OS X Server)

postgresqlosx-mountain-lionpostgresql-9.2osx-server

提问by Pamela Cook - LightBe Corp

I just upgraded my MacMini Server from Lion Server to Mountain Lion using OS X Server. I am having the same problem with PostgreSQL that I did last year when I first installed Lion Server.

我刚刚使用 OS X Server 将我的 MacMini 服务器从 Lion Server 升级到 Mountain Lion。我在去年第一次安装 Lion Server 时遇到了与 PostgreSQL 相同的问题。

When I try to do any kind of PostgreSQL terminal command I get the following notorious error message that many have gotten over the years:

当我尝试执行任何类型的 PostgreSQL 终端命令时,我收到以下臭名昭著的错误消息,多年来许多人都收到了这些消息:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I was attempting to change the password for _postgres when I got the error. I tried several commands but got the same error. I just rebooted my server but no luck. I logged in as root to look at /var/pgsql_socket and the folder is empty. Folder /var/pgsql_socket_alt is also empty.

当我收到错误消息时,我试图更改 _postgres 的密码。我尝试了几个命令,但得到了同样的错误。我刚刚重新启动了我的服务器,但没有运气。我以 root 身份登录以查看 /var/pgsql_socket 并且该文件夹为空。文件夹 /var/pgsql_socket_alt 也是空的。

I have checked online about this. However just about all of the solutions I have read, including on Stack Overflow, suggest a removal and reinstall of PostgreSQL. I do not know but this does not seem like a plausible option because several options on the Server App use PostgreSQL. I contacted Apple Enterprise Support (no agreement) and I was told that my issue would have to be solved by the developers which would cast $695.

我已经在网上查过这个。然而,我读过的几乎所有解决方案,包括 Stack Overflow,都建议删除并重新安装 PostgreSQL。我不知道,但这似乎不是一个合理的选项,因为服务器应用程序上的几个选项使用 PostgreSQL。我联系了 Apple Enterprise Support(未达成协议),并被告知我的问题必须由开发人员解决,开发人员将支付 695 美元。

I have a website that is down right now because I cannot rebuild it. I don't know where to turn for help with this at this point. I will continue looking online to see if I can find something. However I hope that someone can give me an answer quick so I can rebuild my database.

我有一个网站现在关闭了,因为我无法重建它。我不知道在这一点上向哪里寻求帮助。我会继续在网上寻找,看看我是否能找到一些东西。但是我希望有人能快速给我一个答案,这样我就可以重建我的数据库。

Update: 12/13/2012 15:33 GMT-6

更新:12/13/2012 15:33 GMT-6

Here is my output for ps auwwx|grep postg:

这是我的 ps auwwx|grep postg 输出:

_postgres      28123   0.0  0.1  2479696   7724   ??  Ss    3:01PM   0:00.04 /Applications/Server.app/Contents/ServerRoot/usr/bin/postgres_real -D /Library/Server/PostgreSQL For Server Services/Data -c listen_addresses= -c log_connections=on -c log_directory=/Library/Logs/PostgreSQL -c log_filename=PostgreSQL_Server_Services.log -c log_line_prefix=%t  -c log_lock_waits=on -c log_statement=ddl -c logging_collector=on -c unix_socket_directory=/Library/Server/PostgreSQL For Server Services/Socket -c unix_socket_group=_postgres -c unix_socket_permissions=0770
server1        28216   0.0  0.0  2432768    620 s000  R+    3:02PM   0:00.00 grep postg
_postgres      28138   0.0  0.0  2439388    752   ??  Ss    3:01PM   0:00.01 postgres: stats collector process                           
_postgres      28137   0.0  0.0  2479828   1968   ??  Ss    3:01PM   0:00.00 postgres: autovacuum launcher process                           
_postgres      28136   0.0  0.0  2479696    544   ??  Ss    3:01PM   0:00.00 postgres: wal writer process                           
_postgres      28135   0.0  0.0  2479696    732   ??  Ss    3:01PM   0:00.01 postgres: writer process                           
_postgres      28134   0.0  0.0  2479696    592   ??  Ss    3:01PM   0:00.00 postgres: checkpointer process                           
_postgres      28131   0.0  0.0  2439388    368   ??  Ss    3:01PM   0:00.00 postgres: logger process 

Update: 12/13/2012 18:10 GMT-6

更新:12/13/2012 18:10 GMT-6

After intense web searching this video was found. I was able to get PostgreSQL working and remove the error. I am able to connect using pgadmin and phppgadmin. I was about to go back to Lion Server because of sheer frustration. Now I will not have to.

经过激烈的网络搜索,找到了这个视频。我能够让 PostgreSQL 工作并消除错误。我可以使用 pgadmin 和 phppgadmin 进行连接。由于纯粹的挫败感,我正要回到 Lion Server。现在我不必了。

http://www.youtube.com/watch?v=y1c7WFMMkZ4

http://www.youtube.com/watch?v=y1c7WFMMkZ4

回答by mmasters

I was able to add the following to my .bash_profile to prevent the error:

我能够将以下内容添加到我的 .bash_profile 以防止出现错误:

export PGHOST=localhost

This works because:

这是有效的,因为

If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

如果省略主机名,psql 将通过 Unix 域套接字连接到本地主机上的服务器,或通过 TCP/IP 连接到没有 Unix 域套接字的机器上的 localhost。

Your OS supports Unix domain sockets, but PostgreSQL's Unix socket that psqlneeds either doesn't exist or is in a different location than it expects.

您的操作系统支持 Unix 域套接字,但需要的 PostgreSQL Unix 套接字psql要么不存在,要么位于与预期不同的位置。

Specifying a hostname explicitly as localhostforces psqlto use TCP/IP. Setting an environment variable PGHOSTis one of the ways to achieve that. It's documented in psql's manual.

明确指定主机名以localhost强制psql使用 TCP/IP。设置环境变量PGHOST是实现这一目标的方法之一。它记录在psql 的手册中

回答by Bryan Algutria

Try paste in console this:

尝试在控制台中粘贴:

$ mkdir /var/pgsql_socket/ 

$ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/

回答by Nick Woodhams

I was able to solve by simply filling in 127.0.0.1 for the PostgreSQL host address rather than leaving it blank. (Django Example)

我可以通过简单地为 PostgreSQL 主机地址填写 127.0.0.1 而不是将其留空来解决。(Django 示例)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'database_name',
        'USER': 'database_user',
        'PASSWORD': 'pass',
        'HOST': '127.0.0.1',
        'PORT': '',
        }
}

回答by Craig Thomas

Open 'postgresql.conf' in you favourite editor. Look for the variable 'unix_socket_directories', it will most likely look like this:

在您喜欢的编辑器中打开“postgresql.conf”。查找变量“unix_socket_directories”,它很可能如下所示:

unix_socket_directories = '/private/tmp/'

Change the line to this:

将行更改为:

unix_socket_directories = '/var/pgsql_socket/'

Note if you want the socket files in more than one directory comma separate them.

请注意,如果您希望多个目录中的套接字文件以逗号分隔。

回答by Jan Gerritsen

A much more simple solution (thanks to http://daniel.fone.net.nz/blog/2014/12/01/fixing-connection-errors-after-upgrading-postgres/) . I had upgraded to postgres 9.4. In my case, all I needed to do (after a day of googling and not succeeding)

一个更简单的解决方案(感谢http://daniel.fone.net.nz/blog/2014/12/01/fixing-connection-errors-after-upgrading-postgres/)。我已经升级到 postgres 9.4。就我而言,我需要做的就是(经过一天的谷歌搜索但没有成功)

gem uninstall pg
gem uninstall activerecord-postgresql-adapter
bundle install

Restart webrick, and done!

重启 webrick,大功告成!

回答by David Battersby

As mentioned by others in the comments, a really simple solution to this issue is to declare the database 'host' within the database configuration. Adding this answer just to make it a little more clear for anyone reading this.

正如其他人在评论中提到的,这个问题的一个非常简单的解决方案是在数据库配置中声明数据库“主机”。添加此答案只是为了让阅读本文的任何人都更加清楚。

In a Ruby on Rails app for example, edit /config/database.yml:

例如,在 Ruby on Rails 应用程序中,编辑 /config/database.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: database_name
  pool: 5
  host: localhost

Note: the last line added to specify the host. Prior to updating to Yosemite I never needed to specify the host in this way.

注意:添加最后一行以指定主机。在更新到 Yosemite 之前,我从不需要以这种方式指定主机。

Hope this helps someone.

希望这可以帮助某人。

Cheers

干杯

回答by Sivakumar R.J

Check for the status of the database:

检查数据库的状态:

service postgresql status

If the database is not running, start the db:

如果数据库未运行,请启动数据库:

sudo service postgresql start

回答by Hunter

Can you check your postgresql.conf file ??

你能检查一下你的 postgresql.conf 文件吗??

On what port your postgres is running ??

您的 postgres 在哪个端口上运行?

I think it is not running on port 5432.If not change it to 5432

我认为它没有在端口 5432 上运行。如果没有将其更改为 5432

OR on terminal use

或在终端使用

psql -U  postgres -p YOUR_PORT_NUMBER database_name

回答by Ashwin Balamohan

I had this problem with Django.

我在 Django 上遇到了这个问题。

Fix it by explicitly setting your hostname to "localhost".

通过将您的主机名显式设置为“localhost”来修复它。

回答by mymusise

i make in word by doing this:

我这样做:

dpkg-reconfigure locales

and choose your preferred locales

并选择您喜欢的语言环境

pg_createcluster 9.5 main --start

(9.5 is my version of postgresql)

(9.5 是我的 postgresql 版本)

/etc/init.d/postgresql start

and then it word!

然后它的词!

sudo su - postgres
psql