postgresql 无法连接到 Postgres 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40532399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to connect to server for Postgres
提问by SySyBy
I have a problem to connect server for Postgres after I updated my windows.Before I update there is no problem to open the database. My database in Postgres also gone. When I want to create my new database it show this error:
我在更新 Windows 后连接 Postgres 的服务器时遇到问题。在更新之前,打开数据库没有问题。我在 Postgres 中的数据库也不见了。当我想创建我的新数据库时,它会显示此错误:
Unable to connect to server: 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?
无法连接到服务器:无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?无法连接到服务器:连接被拒绝 (0x0000274D/10061) 服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?
回答by Franc Drobni?
There are two items to configure if your server isn't on localhost:
如果您的服务器不在本地主机上,则有两个项目需要配置:
- find your
postgresql.conf
and add your server's public IP address to the end of the settinglisten_addresses
(separate multiple entries by commas); uncomment the line if it is commented out (e.g. with '#') - add a line to
pg_hba.conf
containing your client's IP address - you may copy the line containing 127.0.0.1 and change only the IP address
- 找到您
postgresql.conf
的服务器的公共 IP 地址并将其添加到设置的末尾listen_addresses
(用逗号分隔多个条目);如果该行被注释掉(例如使用“#”),则取消注释该行 - 添加一行以
pg_hba.conf
包含您客户端的 IP 地址 - 您可以复制包含 127.0.0.1 的行并仅更改 IP 地址
On Ubuntu, these files are in /etc/postgresql/<version>/main/
.
在 Ubuntu 上,这些文件位于/etc/postgresql/<version>/main/
.
回答by gagan chhabra
On windows, Just go to the 'Services'. Start/Restart the postgresql-X64 service. It worked for me as my service was in stopped state somehow.
在 Windows 上,只需转到“服务”。启动/重启 postgresql-X64 服务。它对我有用,因为我的服务不知何故处于停止状态。
回答by uosjead
I got this error message when I moved my database to another computer.
当我将数据库移动到另一台计算机时收到此错误消息。
I also got some error messages when starting the server first with
首先使用以下命令启动服务器时,我也收到了一些错误消息
pg_ctl -D /wherever/your/database/is start
pg_ctl -D /wherever/your/database/is start
which were
哪些是
pg_ctl: another server might be running; trying to start server anyway server starting
DETAIL: File "/wherever/your/database/is/PG_VERSION" does not contain valid data.
HINT: You might need to initdb.
pg_ctl:另一台服务器可能正在运行;无论如何都试图启动服务器服务器启动
详细信息:文件“/wherever/your/database/is/PG_VERSION”不包含有效数据。
提示:您可能需要初始化数据库。
In my case rather than running initdb this command actually fixed the issue
在我的情况下,而不是运行 initdb 这个命令实际上解决了这个问题
pg_ctl -D /wherever/your/database/is restart
回答by Damilare Oyediran
I think the problem is with your server listening to default public IP address. For example in the PostgreSQL package, your sever is set to listen to localhost as default public address which when you launch/ run database, the address might be something like '127.0.0.1'
我认为问题在于您的服务器侦听默认公共 IP 地址。例如,在 PostgreSQL 包中,您的服务器设置为侦听 localhost 作为默认公共地址,当您启动/运行数据库时,该地址可能类似于“127.0.0.1”
To fix you can try change localhostto '' as in "listen_addresses = ''".
要修复,您可以尝试将localhost更改为 ' ',如“listen_addresses = ''”。
As seen as "listen_addresses = 'localhost'" under "Connection Settings" in the postgresql.conf file.
如 postgresql.conf 文件中“连接设置”下的“listen_addresses = 'localhost'”所示。
Also to access your postgresql.conf file, go to:
还要访问您的 postgresql.conf 文件,请转到:
On Windows, the file is in /Program Files/PostgreSQL//share/. On Ubuntu, these files are in /etc/postgresql//main/.
在 Windows 上,该文件位于 /Program Files/PostgreSQL//share/ 中。在 Ubuntu 上,这些文件在 /etc/postgresql//main/ 中。
P.S: Changing the defaults 'localhost'; to '*' will let your server listen to any public database address either "localhost, 127.0.0.1 etc.
PS:更改默认值“本地主机”;'*' 将让您的服务器侦听任何公共数据库地址“localhost、127.0.0.1 等”。
I know you might have fix this, just for others that might run into the same issue in the future. Hope it was helpful
我知道你可能已经解决了这个问题,只是为了将来可能遇到同样问题的其他人。希望它有帮助