PostgreSQL 9.2.4 (Windows 7) - 服务无法启动,“无法加载 pg_hba.conf”

PostgreSQL 9.2.4 (Windows 7) - 服务无法启动,“无法加载 pg_hba.conf”

我正在尝试让 Postgres 9.2.4 在 Windows 7 上作为服务运行。安装 postgres 后,该服务运行良好。但是,在将 postgres 设置为另一个程序的服务器后,该服务停止运行。当我现在尝试启动该服务时,我收到一条消息:

“本地计算机上的 postgresql-x64-9.2 - PostgreSQL Server 9.2 服务已启动,然后停止。如果某些服务未被其他服务或程序使用,则会自动停止。”

当我尝试运行应该使用数据库服务器的程序时,出现此错误:

“尝试登录或创建生产数据库时遇到问题。详细信息:无法连接到服务器;无法连接到远程套接字。应用程序现在必须关闭”

我在打开同一个程序时也遇到过一次这个错误:

“尝试登录或创建生产数据库时遇到问题。详细信息:严重错误:无法加载 pg_hba.conf。应用程序现在必须关闭。”

我尝试以本地系统帐户和我自己帐户(在 postgres 服务属性中)的身份运行该服务,但无济于事。我还尝试重新启动计算机。经过大量在线故障排除后,我了解到检查 pg_log 文件是个好主意。以下是最新 pg_log 条目的内容:

2013-05-29 14:59:45 MDT LOG:  database system was interrupted; last known up at 2013-05-29 14:58:01 MDT
2013-05-29 14:59:45 MDT LOG:  database system was not properly shut down; automatic recovery in progress
2013-05-29 14:59:45 MDT LOG:  record with zero length at 0/175BB98
2013-05-29 14:59:45 MDT LOG:  redo is not required
2013-05-29 14:59:45 MDT LOG:  database system is ready to accept connections
2013-05-29 14:59:45 MDT LOG:  autovacuum launcher started
2013-05-29 15:07:00 MDT LOG:  local connections are not supported by this build
2013-05-29 15:07:00 MDT CONTEXT:  line 1 of configuration file "C:/PostgreSQL/data/pg_hba.conf"
2013-05-29 15:07:00 MDT FATAL:  could not load pg_hba.conf
2013-05-29 15:07:00 MDT LOG:  local connections are not supported by this build
2013-05-29 15:07:00 MDT CONTEXT:  line 1 of configuration file "C:/PostgreSQL/data/pg_hba.conf"
2013-05-29 15:07:00 MDT FATAL:  could not load pg_hba.conf
2013-05-29 15:09:03 MDT LOG:  received fast shutdown request
2013-05-29 15:09:03 MDT LOG:  aborting any active transactions
2013-05-29 15:09:03 MDT LOG:  autovacuum launcher shutting down
2013-05-29 15:09:03 MDT LOG:  shutting down
2013-05-29 15:09:03 MDT LOG:  database system is shut down

pg_hba.conf 文件似乎有问题,如下所示:

local all all trust
host all all 127.0.0.1 255.255.255.255 trust
host all all 0.0.0.0 0.0.0.0 trust

根据网上的许多建议,我尝试将顶行编辑为多个不同的替代方案(host all all tr​​ust / host all 127.0.0.1/32 trust / host all 192.168.0.100/24 trust 等)。这对我来说很有意义,因为日志文件说 postgres 不支持本地连接,并且也指向该行。但是,我所做的任何更改都没有任何效果。每次更改后我都尝试重新启动计算机,但没有任何变化。

当我搜索 pg_hba.conf 文件通常是什么样子的示例时,这些示例看起来与我的文件略有不同。我注意到,在 PostgreSQL 程序文件中,除了 pg_hba.conf 之外,还有一个“20130529-150444-old-pg_hba.conf”文件,它看起来更像我在网上找到的示例。此文件在最后几行之前有几行注释:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

我希望这是原始的 pg_hba.conf 文件,如果我用旧文件的内容替换新文件,postgres 就会重新开始工作。但运气不佳。我一直希望在 pg_log 中记录更多错误文件,以查看先前所述的错误是否消失或更改为其他内容,但没有记录更多文件。

我已经在线排除故障几天了,但找不到任何有效的方法。很抱歉问了这么长的问题,但我想把所有相关信息都写清楚。如果有人能解释一下这个问题或提出建议,我将不胜感激。

答案1

  1. initdb以前跑过步吗?

    如果没有,则会导致问题。运行该initdb命令后,您将看到一个data目录,其中应包含default pg_hba.conf

  2. 然后您需要default pg_hba.conf用您的替换customized pg_hba.conf

  3. 您需要设置 $PGDATA。在 CentOS 中,它位于/etc/sysconfig/pgsql/postgresql

相关内容