PostgreSQL:无法连接到服务器-连接被拒绝错误 [英] PostgreSQL: could not connect to server - Connection refused error

查看:5036
本文介绍了PostgreSQL:无法连接到服务器-连接被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我无法设置 postgreSQL 来与我的 Ruby-on-Rails 项目一起使用周。
我尝试两次卸载并重新安装 postgreSQL
但是当我尝试启动 postgreSQL 我不断收到以下错误:

I've failed to set up postgreSQL to work with my Ruby-on-Rails project for the past week.
I've tried to uninstall and reinstall, postgreSQL, twice now.
But when I try to launch postgreSQL I keep getting the error below:

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 文件的关键部分如下所示:

I've looked at many online resources, including stackoverflow and none seem helpful.
The key parts of my pg_hba.conf file looks like this:

# 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 文件的关键部分如下:

And the key part of my postgresql.conf file is as follows:

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,但这没有帮助。有人对我有什么建议吗?谢谢!

Most of the suggestions, I've seen so far, were based on those two files. (For my case, they were already configured correctly). I also tried disabling the firewall and restarting postgreSQL but it didn't help. Does anyone have any suggestions for me? Thanks!

推荐答案

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

Got the same issue while settings up PostgreSQL 9.6.16 to work with Python/Django, but this is purely a database issue.


解决方案在于错误:实际上,我发现此错误是在官方内部提到的 PostgreSQL文档,因此这是一个常见错误。

The solution lies in the error: In fact, I found this error mentioned within the official PostgreSQL documentation thus it's a common error.

这是我解决此问题的方法:

And here is how I resolved this issue:


  1. 始终首先启动postgres 数据库服务器,使用 postgres 或包装程序 pg_ctl
    我在下面使用了以下命令:在 windows 10 上。
    请记住, -D 之后的所有内容都应是安装PostgreSQL的路径。 ,到数据文件夹,其中包含 pg_hba.conf postgresql.conf 文件。

  1. Always first start the postgres database server, use postgres or the wrapper program pg_ctl.
    I used the command, below, on windows 10.
    Remember, whatever comes after -D should be the path to where you installed PostgreSQL, to the data folder, which holds the pg_hba.conf and postgresql.conf files.



> pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"




  1. 如果运行良好,则准备就绪即可访问数据库服务器。
    打开另一个 cmd shell,然后在下面键入命令。
    记住密码您在安装 PostgreSQL 时输入的密码?
    在询问用户postgres的密码时,输入该密码:

  1. If that runs well, you are ready to access the database server.
    Open another cmd shell, and type the command below.
    Remember the password you entered while installing PostgreSQL?
    Enter that password when asked Password for user postgres:



> psql -U postgres

完成后,您现在可以继续进行创建角色 CREATE DATABASE 相应。

Once done, you can now go ahead to CREATE ROLE and CREATE DATABASE accordingly.

这篇关于PostgreSQL:无法连接到服务器-连接被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆