为什么 Rails Postgresql 不允许我启动我的 rails 应用程序?

Why does Rails Postgresql not allow me to start my rails app?

我目前正在尝试通过 Heroku 部署我的 Rails 应用程序。为此,我需要从 sqlite3 切换到 postgresql。我这样做了,并尝试通过执行“rails s”来测试 运行 应用程序。但是,我的浏览器出现以下错误:

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

也说明错误发生在这里:

    ### Convenience alias for PG::Connection.new.
    def self::connect( *args )
        return PG::Connection.new( *args ) <<< (error in this line)
    end

如有任何帮助,我们将不胜感激。谢谢!

根据 Postgres 的安装方式,听起来您需要重新启动 Postgres。

使用 brew:

brew services restart postgresql

使用 asdf:

pg_ctl stop
pg_ctl start

有时您可能需要重新安装 pg gem。