postgresql PG::ConnectionBad:致命:用户“alphauser”的密码验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28793606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:48:23  来源:igfitidea点击:

PG::ConnectionBad: FATAL: password authentication failed for user "alphauser"

ruby-on-railspostgresqlauthentication

提问by Madalina

I'm working on an application in Rails for my college. The application was started by the students from previous year and now it's me and my colleagues turn to continue work on it. I took the application from github, I run bundle install, but when to run rake db:migrateI got this PG::ConnectionBad: FATAL: password authentication failed for user "alphauser". In database.yml I have these

我正在为我的大学编写 Rails 应用程序。申请是由前一年的学生开始的,现在轮到我和我的同事继续研究了。我从 github 上获取了应用程序,我运行了 bundle install,但是什么时候运行rake db:migrate我得到了这个PG::ConnectionBad: FATAL: password authentication failed for user "alphauser". 在 database.yml 我有这些

 development:
  adapter: postgresql
  encoding: unicode
  database: alpha_database
  host: localhost
  pool: 5
  username: alphauser
  password: alphapassword

I don't know what to do in this case.

在这种情况下,我不知道该怎么办。

回答by Mikhail Chuprynski

You have to create corresponding user and database manually like this:

您必须像这样手动创建相应的用户和数据库:

in shell: psql

在外壳中: psql

then:

然后:

  create user alphauser with password 'alphapassword';
  create database alpha_database owner alphauser;
  alter user alphauser superuser createrole createdb replication;
  \q

don't forget semicolons.

不要忘记分号。

回答by Salma Gomaa

Try to use:

尝试使用:

sudo -u postgres createuser --interactive --pwprompt

sudo -u postgres createuser --interactive --pwprompt

to add the role and the password

添加角色和密码

回答by george

So the problem is with your rails application using the database.ymlfile to try and connect to your local database and failing to find the user alphauser(since I assume you're using different computers/environments as the previous students).

所以问题在于您的 rails 应用程序使用该database.yml文件尝试连接到您的本地数据库,但未能找到用户alphauser(因为我假设您使用的是与以前的学生不同的计算机/环境)。

Databases have users similar to applications, the postgres documentation is pretty dense on this, but I would guess if you can create a user alphauser, and make it's password alphapasswordthen you will have a new clean database for your app that you can run rake db:migrateon.

数据库有类似于应用程序的用户,postgres 文档在这方面非常密集,但我想如果您可以创建一个 user alphauser,并设置它的密码,alphapassword那么您将拥有一个新的干净的应用程序数据库,您可以在其rake db:migrate上运行。

Postgres docs: http://www.postgresql.org/docs/9.2/static/app-createuser.html

Postgres 文档:http: //www.postgresql.org/docs/9.2/static/app-createuser.html

Try running this command from the command line createuser -P -s -e alphauser

尝试从命令行运行此命令 createuser -P -s -e alphauser

This will prompt for a password, which is alphauserpassword

这将提示输入密码,即 alphauserpassword

回答by vidur punj

 create user alphauser with password 'alphapassword';

Then

然后

rake db:setup