首页 > 解决方案 > 在 Ubuntu 上为 WSL 配置 postgresql 到 rails 时遇到问题

问题描述

所以我在 Ubuntu 上为 WSL 使用 VS 代码并从 GitHub 分叉一个 rails 应用程序,当我尝试运行时rails db:set up,它给了我这个错误:

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'development_database' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

...traces...

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我试着跑service postgresql status,我得到了10/main (port 5432): down

当我尝试时dpkg -l | grep postgres,我得到了这个:

ii  postgresql                     10+190ubuntu0.1                    all          object-relational SQL database (supported version)
ii  postgresql-10                  10.10-0ubuntu0.18.04.1             amd64        object-relational SQL database, version 10 server
ii  postgresql-client              10+190ubuntu0.1                    all          front-end programs for PostgreSQL (supported version)
ii  postgresql-client-10           10.10-0ubuntu0.18.04.1             amd64        front-end programs for PostgreSQL 10
ii  postgresql-client-common       190ubuntu0.1                       all          manager for multiple PostgreSQL client versions
ii  postgresql-common              190ubuntu0.1                       all          PostgreSQL database-cluster manager
ii  postgresql-contrib             10+190ubuntu0.1                    all          additional facilities for PostgreSQL (supported version)

这是否意味着问题是我的服务器没有运行?我应该怎么做才能运行服务器或创建数据库?

标签: ruby-on-railsdatabasepostgresqlubuntu

解决方案


这意味着您的服务器已安装但未运行。尝试

service postgresql start 

启动服务器。

要检查您的实例是否正在运行,请尝试运行

psql -U postgres -d postgres

除非您弄乱了 HBA 配置,否则应该将您连接到postgres角色中的本地数据库(默认管理数据库)postgres


推荐阅读