简体   繁体   English

本地 PostgresSQL 中的“连接被拒绝”,但它以前工作过

[英]"Connection refused" in Local PostgresSQL but it worked before

I am not a programmer, I do my best, but I need help.我不是程序员,我尽力了,但我需要帮助。 I created and managed postgressql DB for my department needs on localhost, Windows.我在 localhost、Windows 上为我的部门需求创建和管理了 postgressql 数据库。 I set required ip to listens in postgresql.conf and configured pg_hba.conf.我将所需的 ip 设置为在postgresql.conf 中侦听并配置了pg_hba.conf。 And it worked fine for 3 months.并且它工作了 3 个月。

But today I came to work, tried to connect to Postgresql server.但是今天我来上班,尝试连接到 Postgresql 服务器。 And see this:看看这个:

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?无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?

I checked configs - there are no changes.我检查了配置 - 没有变化。 I tested settings with listened_ip='*'.我用 listened_ip='*' 测试了设置。 Still not working.还是行不通。 And I see that message when i try to create new server.当我尝试创建新服务器时,我看到了该消息。

What happened?发生了什么? How to fix all this?如何解决这一切?

Assuming you have not alteres pg_hba.conf file, you can start your postgres from windows cmd.exe using假设您没有更改 pg_hba.conf 文件,您可以使用 Windows cmd.exe 从 Windows cmd.exe 启动您的 postgres

net start postgresql-9.8

instead of 9.8, you use your postgres version number.而不是 9.8,你使用你的 postgres 版本号。 Other way round you can look for your services from (start -> run -> services.msc)反过来,您可以从(开始-> 运行-> services.msc)查找您的服务

The general thought/assumptions:一般想法/假设:

It looks like it is pgAdmin (probably version 4) or your admin rights or one of the files mentioned above (postgresql.conf and/or pg_hba.conf).看起来它是 pgAdmin(可能是第 4 版)或您的管理员权限或上述文件之一(postgresql.conf 和/或 pg_hba.conf)。

I had the same error and even a password error (for the correct password) after being a step further by some todo's and fixes that helped other people in previous versions;我遇到了同样的错误,甚至出现了密码错误(正确的密码),但在更进一步的一些待办事项和修复程序之后,在以前的版本中帮助了其他人;

But none of them worked for postgresql version 12.3 and/or postgresql version 11.8但是它们都不适用于postgresql 12.3 版和/或postgresql 11.8 版

Solution versions:解决方案版本:

The only thing that helped after two hours was: As explained in this post: ' PostgreSQL Install fail on Windows 10 (icalcs error/acces denied) ' on the superuser forum of StackExchange:两小时后唯一有帮助的是:正如这篇文章中所解释的: StackExchange超级用户论坛上的“ PostgreSQL 安装在 Windows 10 上失败(icalcs 错误/访问被拒绝) ”:

  • Uninstall en reinstall postgresql.卸载并重新安装 postgresql。 The official version provided by EDB through this link: postgresql.org/download ; EDB通过这个链接提供的官方版本: postgresql.org/download Or try a different version if you are sure this one doesn't work for you.或者,如果您确定此版本不适合您,请尝试其他版本。 Therefor head to the 'File Browser'of Postgresql: here因此前往 Postgresql 的“文件浏览器”:这里
  • After reinstall, start pgAdmin from the Start Menu (scroll for the folder and the correct related pgAdmin; an older version could still hang around in the shortcuts and won't start).重新安装后,从“开始”菜单启动 pgAdmin (滚动文件夹和正确的相关 pgAdmin;旧版本仍然会在快捷方式中徘徊并且无法启动)。

Note: You can keep your data map so nothing is lost!注意:您可以保留您的数据地图,因此不会丢失任何内容!

In my case eg: I removed the /data folder from the (Windows 10) [Drive]/Program Files/PostgreSQL/11 and as soon as I uninstalled version 11.2 and reinstalled (earlier removed 12) version 12: when I started pgAdmin4 my former servers ([nameA] and [PostgreSQL 11] and databases ánd the new server [PostgreSQL 12] were there! And the connection was reestablished就我而言,例如:我从(Windows 10)[驱动器]/Program Files/PostgreSQL/11 中删除了 /data 文件夹,并且在我卸载 11.2 版并重新安装(较早删除的 12)版本 12 后:当我启动 pgAdmin4 时,我的以前的服务器([nameA] 和 [PostgreSQL 11] 以及数据库和新服务器 [PostgreSQL 12] 在那里!并且重新建立了连接

Tried:尝试:

Earlier tried solutions that did not work in my case:之前尝试过的解决方案在我的情况下不起作用:

if you've installed the official postgreSQL on Windows accepting all default settings, maybe you need to manually start the service (Run cmd.exe as admin and enter this command) each time you start querying:如果你在 Windows 上安装了官方的 postgreSQL,接受所有默认设置,也许你每次开始查询时都需要手动启动服务(以管理员身份运行 cmd.exe 并输入此命令):

pg_ctl -D "C:\Program Files\PostgreSQL\[YOUR_POSTGRESQL_VERSION]\data" start

in my case is:在我的情况下是:

pg_ctl -D "C:\Program Files\PostgreSQL\12\data" start

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM