简体   繁体   English

嗨,我正在尝试在 WSL Ubuntu 中运行 rails db:create 并不断收到有关 postgres 的此错误

[英]Hi I am trying to run rails db:create in WSL Ubuntu and keep getting this error in regards to postgres

This is my first time trying to set up postgres with rails and have tried so many different ways to get this working.这是我第一次尝试使用 rails 设置 postgres,并尝试了很多不同的方法来让它工作。 Please help!请帮忙!

Error:错误:

could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
Couldn't create 'backend_development' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

database.yml:数据库.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  username: postgres
  password: password
  host: localhost
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

When I run psql i receive this error again:当我运行 psql 时,我再次收到此错误:

psql: error: could not connect to server: 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"?

Do you have PostgreSQL installed properly?您是否正确安装了 PostgreSQL? To check the version $ postgres --version .检查版本$ postgres --version If it's not installed on your system run $ sudo apt-get install postgresql postgresql-contrib libpq-dev如果您的系统上未安装它,请运行$ sudo apt-get install postgresql postgresql-contrib libpq-dev

If you have it installed login with如果你已经安装了登录

$sudo su - postgres

Then create a new user after logged in然后登录后创建一个新用户

$ createuser --pwprompt username

now create the database现在创建数据库

$ createdb -O username database_name . $ createdb -O username database_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM