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

Rails 6.0.6连接PostgreSQL触发connection_pool.rb段错误求助

解决方案

针对M1芯片Mac上Rails 6.0.6连接PostgreSQL 12.15触发段错误的问题,无需禁用gssencmode的修复方案如下:

  • 重新编译pg gem,绑定Homebrew PostgreSQL路径
    M1芯片上pg gem可能默认使用了不兼容的PostgreSQL客户端库,重新指定Homebrew的pg配置编译:

    gem uninstall pg
    gem install pg -- --with-pg-config=$(brew --prefix postgresql@12)/bin/pg_config
    

    确保pg gem使用Homebrew安装的arm架构PostgreSQL库,避免跨架构兼容问题。

  • 配置动态库加载路径
    在你的shell配置文件(~/.zshrc或~/.bashrc)中添加环境变量,让Ruby优先加载Homebrew的PostgreSQL库:

    export DYLD_LIBRARY_PATH="$(brew --prefix postgresql@12)/lib:$DYLD_LIBRARY_PATH"
    

    执行source ~/.zshrc(对应你的shell)使配置生效。

  • 升级PostgreSQL到兼容M1的新版本
    PostgreSQL 12属于旧版本,在M1架构上兼容性有限,建议升级到14+版本(以postgresql@14为例):

    1. 备份现有数据库:
      pg_dumpall > backup.sql
      
    2. 卸载旧版本并安装新版:
      brew uninstall postgresql@12
      brew install postgresql@14
      
    3. 迁移备份数据:
      psql -d postgres -f backup.sql
      
    4. 更新database.yml中的数据库端口(新版默认端口可能为5433,需对应调整)。
  • 确保Ruby为arm64架构版本
    执行ruby -e "puts RUBY_PLATFORM",若输出为x86_64-darwin22说明是Rosetta运行的x86 Ruby,会和arm版PostgreSQL冲突。用rbenv/asdf重新安装arm版Ruby 2.7.8:

    # 以rbenv为例,需先确保安装了openssl@1.1
    RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" rbenv install 2.7.8
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 12:35:16