You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

苹果芯片Mac通过Homebrew安装PostgreSQL及报错解决咨询

苹果芯片Mac通过Homebrew安装PostgreSQL及报错解决方案

报错核心原因

设备上同时存在官方dmg安装的PostgreSQL、x86架构下Homebrew安装的PostgreSQL两个版本,出现文件冲突、服务配置不兼容的问题,同时强制使用x86架构安装不符合苹果芯片的运行要求。

正确安装步骤

  • 优先使用苹果芯片原生Homebrew(默认安装路径为/opt/homebrew,不要添加arch -x86_64前缀执行brew命令)
  • 先完全卸载所有旧版本PostgreSQL:
    1. 卸载x86架构Homebrew安装的版本:arch -x86_64 brew uninstall --force postgresql
    2. 卸载官方dmg安装的版本:打开/Library/PostgreSQL目录,运行目录内的uninstall-postgres.app完成卸载,删除对应安装目录
    3. 清理残留文件:
      rm -rf ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
      rm -rf /usr/local/var/postgres /opt/homebrew/var/postgres /tmp/.s.PGSQL.5432*
      
  • 执行原生Homebrew安装命令:brew install postgresql
  • 初始化数据库:initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres
  • 启动PostgreSQL服务:brew services start postgresql
  • 验证安装:执行psql postgres可正常进入PostgreSQL命令行即为安装成功。

对应报错解决方法

1. psql连接拒绝报错

psql: error: could not connect to server: Connection refused Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

  • 触发逻辑:PostgreSQL服务未正常启动,或是多版本残留导致socket文件被占用、psql命令与运行的服务版本不匹配
  • 修复步骤:
    • 执行ps aux | grep postgres查询正在运行的PostgreSQL进程,所有进程执行kill -9 进程ID终止
    • 删除残留socket文件:rm -f /tmp/.s.PGSQL.5432*
    • 按上述完整卸载重装步骤操作即可解决

2. brew services启动报错

Bootstrap failed: 5: Input/output error Error: Failure while executing; /bin/launchctl bootstrap gui/501 /Users/rajanlagah/Library/LaunchAgents/homebrew.mxcl.postgresql.plist exited with 5.

  • 触发逻辑:旧版本PostgreSQL的launchctl服务配置文件残留,新安装的版本与旧配置不兼容,x86架构的服务在苹果芯片上无法正常加载
  • 修复步骤:
    • 停止所有版本的PostgreSQL服务:
      brew services stop postgresql
      arch -x86_64 brew services stop postgresql
      
    • 删除残留服务配置:rm -f ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    • 卸载旧配置:launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 2>/dev/null
    • 完成完整卸载重装后使用原生Homebrew启动服务即可恢复

内容的提问来源于stack exchange,提问作者Rajan Lagah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 05:15:03