繁体   English   中英

无法连接到服务器 postgresql 错误

[英]Unable to connect to server postgresql error

我无法连接到 postgresql 服务器。 直到昨天连接工作正常,但从今天早上开始我遇到了这个问题。 我使用自制软件安装了 postgres,并且已经卸载并重新安装了它。 下面是 pgAdmin 4 的截图:

在此处输入图像描述

我找不到 postgresql.conf 和 pg_hba.conf,因为有多种解决方案建议更改 listen_addresses。 我看到安装了 postgresql,这是位置:/opt/homebrew/Cellar/postgresql@14。 我尝试过以下解决方案: 如何在 Mac OS X 上启动 PostgreSQL 服务器? 但几乎所有命令我都收到错误:警告:定位数据库(/var/db/locate.database)不存在。 要创建数据库,请运行以下命令:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

请注意,生成数据库可能需要一些时间; 创建数据库后,此消息将不再出现。

如果我尝试更改命令中的位置( https://stackoverflow.com/questions/7975556/how-can-i-start-postgresql-server-on-mac-os-x#:~:text=I%20start% 20the-,PostgreSQL,-server%3F )启动服务器,我得到错误:pg_ctl:目录“/opt/homebrew/postgres_db_cluster”不存在。

最糟糕的是,直到昨天它都运行良好。 任何帮助表示赞赏。

编辑 1:正如评论中所建议的,我按照https://wiki.postgresql.org/wiki/Homebrew中的步骤操作,但仍然出现错误。 第一步:brew services restart postgresql@14 ==> 成功停止postgresql@14 (标签:homebrew.mxcl.postgresql@14)==> 成功启动postgresql@14 (标签:homebrew.mxcl.postgresql@14) 第二步: psql postgrespsql:错误:连接到套接字“/tmp/.s.PGSQL.5432”上的服务器失败:没有这样的文件或目录服务器是否在本地运行并接受该套接字上的连接?

编辑2:我尝试了这个解决方案的第一步: https://stackoverflow.com/questions/7975556/how-can-i-start-postgresql-server-on-mac-os-x?rq=1#:~ :text=on%20port%205432%3F-,Update,-3%3A下面是结果:

abhinash.kumar@ ~ % pg_ctl -D /usr/local/var/postgres status
pg_ctl: directory "/usr/local/var/postgres" is not a database cluster directory.

此外,该链接提到了一个文件 pg_hba.conf.sample,但我在我的系统中找不到它。

编辑 3:使用自制软件启动 postgres 服务器

abhinash.kumar@ ~ % brew services start postgresql@14     
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/abhinash.kumar/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

继续抛出错误。

感谢https://stackoverflow.com/users/7070613/adrian-klaver ,现在问题已得到解决。 我卸载了 postgres,并使用自制软件重新安装。 另外,我运行了这个命令:initdb -D /usr/local/var/postgres/。 这解决了这个问题,我可以使用 pgAdmin 4 创建数据库连接。

暂无
暂无

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

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