【问题标题】:postgres: localhost not connectingpostgres:本地主机未连接
【发布时间】:2013-03-26 18:36:15
【问题描述】:

我的postgreSQL.conf 看起来像

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 5432                             # (change requires restart)

我也知道 postgres 正在运行

air:data postgres$ ps -aef | grep postgres
  504 16474 16473   0 11:34AM ??         0:00.00 postgres: logger process
  504 16476 16473   0 11:34AM ??         0:00.00 postgres: writer process
  504 16477 16473   0 11:34AM ??         0:00.00 postgres: wal writer process
  504 16478 16473   0 11:34AM ??         0:00.00 postgres: autovacuum launcher process
  504 16479 16473   0 11:34AM ??         0:00.00 postgres: stats collector process
    0 16087 16078   0 10:54AM ttys001    0:00.03 su - postgres
  504 16473     1   0 11:34AM ttys001    0:00.22 /Library/PostgreSQL/9.1/bin/postgres -D/Library/PostgreSQL/9.1/data
  504 16484 16088   0 11:34AM ttys001    0:00.00 grep postgres

但我无法连接

 psql -Uuser -W
Password for user user:
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"?

另外,当我运行以下命令时

 lsof -i tcp:5432
 ✘ me@air11:37:13 ⮀ ~ ⮀ netstat -a | grep postgres
tcp6       0      0  *.postgres             *.*                    LISTEN
tcp4       0      0  *.postgresql           *.*                    LISTEN

它没有说在port 5432上运行 我错过了什么?

更新

我的pg_hba.conf 看起来像

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

【问题讨论】:

  • 您是否在使用 Mac OS X 机器? (通常最好提及您的平台)
  • 我的错,是的,我使用的是 Mac OS X

标签: postgresql postgresql-9.1


【解决方案1】:

在 pg_hba.conf 中:

host    all             all             127.0.0.1/32            trust

最后一列更改为trust

【讨论】:

    【解决方案2】:

    您需要使用您安装的 PostgreSQL 软件包随附的 psql 程序,而不是 Apple 系统中 /usr/bin 目录中的 psql

    例如,如果使用postgres.app,他们会在documentation 中说:

    Mac OS 10.7 附带旧版本的 PostgreSQL,可以 从以下命令开始:

    $ psql -h localhost PostgreSQL 附带了一系列有用的 您可能想要的二进制文件,例如 pg_dump 或 pg_restore 利用。继续添加 Postgres.app 附带的 /bin 目录 到您的 PATH(最好在 .profile、.bashrc、.zshrc 等中) 确保为每个终端会话设置此项):

    PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
    一旦你 路径设置正确,您应该能够在没有 主持人。 (如果没有,请检查是否正在加载正确的版本 PATH 通过执行 which psql)

    如果使用其他预打包的postgresql源,则路径不同。

    【讨论】:

      【解决方案3】:

      不知道为什么会这样,但我发现postgresapp.com 很好用

      我将它与http://www.pgadmin.org/ 一起使用,到目前为止我运行顺利

      【讨论】:

        【解决方案4】:

        您可以尝试停止服务并重新启动服务。重新加载配置文件后。在它是否工作时再次检查。

        【讨论】:

          猜你喜欢
          • 2019-03-25
          • 2018-02-05
          • 2021-06-11
          • 2015-06-26
          • 1970-01-01
          • 2020-01-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多