简体   繁体   English

PostgreSQL:无法连接到服务器 - 连接被拒绝错误

[英]PostgreSQL: could not connect to server - Connection refused error

I've failed to set up postgreSQL to work with my Ruby-on-Rails project for the past week.过去一周我未能设置postgreSQL来处理我的Ruby-on-Rails项目。
I've tried to uninstall and reinstall, postgreSQL , twice now.我已经尝试卸载并重新安装postgreSQL两次。
But when I try to launch postgreSQL I keep getting the error below:但是当我尝试启动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?"

I've looked at many online resources, including stackoverflow and none seem helpful.我查看了许多在线资源,包括stackoverflow ,但似乎没有任何帮助。
The key parts of my pg_hba.conf file looks like this:我的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

And the key part of my postgresql.conf file is as follows:而我的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

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.我也试过禁用防火墙并重新启动 postgreSQL 但它没有帮助。 Does anyone have any suggestions for me?有人对我有什么建议吗? Thanks!谢谢!

Got the same issue while settings up PostgreSQL 9.6.16 to work with Python/Django, but this is purely a database issue.在设置 PostgreSQL 9.6.16 以使用 Python/Django 时遇到同样的问题,但这纯粹是一个数据库问题。

The solution lies in the error: In fact, I found this error mentioned within the official PostgreSQL documentation thus it's a common error.解决方法在于错误:事实上,我在PostgreSQL官方文档中发现了这个错误,因此这是一个常见错误。

And here is how I resolved this issue:这是我解决这个问题的方法:

  1. Always first start the postgres database server , use postgres or the wrapper program pg_ctl .总是首先启动 postgres数据库服务器,使用postgres或包装程序pg_ctl
    I used the command, below, on windows 10 .我在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.请记住, -D之后的任何内容都应该是您安装 PostgreSQL 的路径、 data文件夹的路径,该文件夹包含pg_hba.confpostgresql.conf文件。
> pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
  1. If that runs well, you are ready to access the database server.如果运行良好,您就可以访问数据库服务器了。
    Open another cmd shell, and type the command below.打开另一个cmd shell,然后键入以下命令。
    Remember the password you entered while installing PostgreSQL ?还记得您在安装PostgreSQL输入的密码吗?
    Enter that password when asked Password for user postgres:当询问Password for user postgres:密码时输入该密码Password for user postgres:
> psql -U postgres

Once done, you can now go ahead to CREATE ROLE and CREATE DATABASE accordingly.完成后,您现在可以继续CREATE ROLE并相应地CREATE DATABASE

[SOLVED] [解决了]

After much more research.经过更多的研究。 I looked in depth at the error I was receiving post downloading and came to this solution here我深入查看了我在下载后收到的错误,并在这里找到了这个解决方案

Best of luck for anyone having the same issue!祝有同样问题的人好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接拒绝PostgreSQL服务器 - Connection refused to PostgreSQL server PostgreSQL:无法连接到服务器:连接超时 - PostgreSQL: could not connect to server: Connection timed out Rails-Postgres-无法连接到服务器:连接被拒绝(PG :: ConnectionBad) - Rails - Postgres - could not connect to server: Connection refused (PG::ConnectionBad) PG::ConnectionBad - 无法连接到服务器:Mac OS X 上的连接被拒绝 - PG::ConnectionBad - could not connect to server: Connection refused on Mac OS X PostgreSQL - 与本地主机的连接:“****”拒绝错误 - PostgreSQL - Connection to localhost:"****" refused error PgAdmin- Postgres:无法连接到服务器:连接被拒绝(0x0000274D/10061) - PgAdmin- Postgres: could not connect to server: Connection refused (0x0000274D/10061) 错误“无法连接到 PostgreSQL 服务器:连接中的“0”后缺少“=” - error with “Unable to connect to PostgreSQL server: missing ”=“ after ”0“ in connection” TALEND:网络错误IOException:连接被拒绝:connect - TALEND: Network error IOException: Connection refused: connect 与postgresql在centOS中拒绝连接 - connection refused in centOS with postgresql MYSQL错误-由于目标计算机被拒绝而无法建立连接 - MYSQL Error - Connection Could Not Be Made Because Target Machine Refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM