4

在过去的一周里,我没有准备好postgreSQL使用我的Ruby-on-Rails项目。
我已经尝试卸载并重新安装postgreSQL, 两次了。
但是当我尝试启动时,postgreSQL我不断收到以下错误:

could not connect to server: Connection refused (0x0000274D/10061)
         Is the server running on host "localhost" (::1) and
         accepting TCP/IP connections on port 5432? 
could not connect to server: Connection refused (0x0000274D/10061) 
         Is the server running on host "localhost" (127.0.0.1) and 
         accepting TCP/IP connections on port 5432?"

我查看了许多在线资源,包括stackoverflow,但似乎没有任何帮助。
我的文件的关键部分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

我的postgresql.conf文件的关键部分如下:

listen_addresses = '*'      # what IP address(es) to listen on;
                    # comma-separated list of addresses;
                    # defaults to 'localhost'; use '*' for all
                    # (change requires restart)
port = 5432             # (change requires restart)
max_connections = 100           # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = ''   # comma-separated list of directories
                    # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation

到目前为止,我看到的大多数建议都是基于这两个文件。(就我而言,它们已经正确配置)。我还尝试禁用防火墙并重新启动 postgreSQL,但没有帮助。有人对我有什么建议吗?谢谢!

4

2 回答 2

5

在设置 PostgreSQL 9.6.16 以使用 Python/Django 时遇到了同样的问题,但这纯粹是一个数据库问题。

解决方案在于错误:事实上,我在PostgreSQL 官方文档中发现了这个错误,因此这是一个常见错误。

以下是我解决此问题的方法:

  1. 总是首先启动 postgres数据库服务器,使用postgres或包装程序pg_ctl
    我在下面使用了命令windows 10
    请记住,后面的内容-D应该是安装 PostgreSQL 的路径data,以及保存pg_hba.confpostgresql.conf文件的文件夹。
> pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
  1. 如果运行良好,您就可以访问数据库服务器了。打开另一个shell,然后键入以下命令。还记得安装时输入的密码吗?询问时输入该密码
    cmd
    PostgreSQL
    Password for user postgres:
> psql -U postgres

完成后,您现在可以继续进行CREATE ROLE相应的操作CREATE DATABASE

于 2019-11-25T13:38:52.080 回答
-2

[解决了]

经过更多的研究。我深入查看了下载后收到的错误,并在这里找到了这个解决方案

祝遇到同样问题的人好运!

于 2016-12-14T00:03:05.623 回答