BER分博客 - PostgreSQL 2026-02-07T05:58:00+00:00 Typecho https://blog.berfen.com/feed/atom/tag/PostgreSQL/ <![CDATA[macOS 环境下 PHP-FPM 连接 PostgreSQL 时崩溃(502 Bad Gateway)的排查与解决]]> https://blog.berfen.com/post/58.html 2026-02-07T05:58:00+00:00 2026-02-07T05:58:00+00:00 taotecode https://blog.berfen.com 问题描述

在 macOS 开发环境中,使用 Homebrew 安装的 PHP 8.2 + PHP-FPM 连接远程 PostgreSQL 数据库时,频繁出现 502 Bad Gateway 错误。

症状特征

  • CLI 模式完全正常:php artisan tinker 或直接运行 PHP 脚本都能成功连接
  • PHP-FPM 模式崩溃:通过 Nginx 访问时,PHP-FPM worker 进程会崩溃
  • Linux 服务器正常:相同的代码在 Linux 生产服务器上运行完全正常
  • 间歇性发生:有时能成功,有时失败,重启 PHP-FPM 后短暂恢复
  • 并发时更容易触发:多个请求同时访问时崩溃概率更高

[...]

]]>