fe_sendauth:未提供密码

118

数据库配置文件 database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: postgresql
  encoding: utf8
  database: sampleapp_dev  #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 

  #adapter: sqlite3
  #database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: postgresql
  encoding: utf8
  database: sampleapp_test  #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 
  #adapter: sqlite3
  #database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: sampleapp_prod   #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 
  #adapter: sqlite3
  #database: db/production.sqlite3
  pool: 5
  timeout: 5000

pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                md5
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

我把前三行的METHOD从md5改成了trust,但是我仍然收到错误信息。

而且无论我在database.yml里尝试什么组合,当我执行以下命令时:

~/rails_projects/sample_app4_0$ bundle exec rake db:create:all

我总是收到以下错误信息:

fe_sendauth: 没有提供密码

我按照这个教程进行设置:

https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux

Mac OSX 10.6.8
PostgreSQL 9.2.4 installed via enterpriseDB installer
Install dir: /Library/PostgreSQL/9.2

1
你在修改后重新加载了pg_hba.conf文件吗? - bma
@bma,你怎么重新加载它?我能够连接到服务器的唯一方法是使用pgAdmin3(在9.2目录中)。我选择服务器,右键单击,然后选择连接。因此,为了重新加载conf文件,我从pgAdmin3中断了与服务器的连接,然后重新连接。 - 7stud
3
您可以以超级用户身份发出查询:“select pg_reload_conf()”,或者在pgadmin中右键单击数据库名称,然后点击“重新加载配置”(我认为这就是它的作用,但我不使用pgadmin)。 - bma
@bma,$!@#%!$ ^%!那个起作用了。你能把你的评论放在答案里吗? - 7stud
1
我曾经遇到过同样的问题。我解决了这个问题,将用户名:postgres和密码:放入我的database.yml文件中。 - Danilo Cândido
6个回答

93

在更改 pg_hba.confpostgresql.conf 文件后,需要重新加载群集以获取更改。

从命令行运行:pg_ctl reload

在数据库内(作为超级用户)运行:select pg_reload_conf();

从PGAdmin:右键单击数据库名称,选择“重新加载配置”

注意:重新加载不足以进行启用归档、更改 shared_buffers 等更改--这些需要重启群集。


2
我有一个后续问题:据我所知,我从未启动过任何服务器。我所做的唯一一件事就是使用Mac OSX安装程序安装了PostgreSQL。然后我花了几个小时试图弄清楚如何使用PostgreSQL,但没有成功。我只是碰巧在/Library/PostgreSQL/9.2目录中发现了pgAdmin3,所以我点击了它。那么服务器是如何启动的?我需要停止它吗? - 7stud
3
这可能是安装程序完成后开始的(大多数我见过的安装程序/软件包都是这样做的)。 - bma
1
我需要停止它吗?我该怎么做?我不喜欢安装程序,因为我习惯使用命令行。 - 7stud
1
停止什么?数据库集群还是安装程序?如果是后者,我不知道为什么安装程序仍在运行。 - bma
4
服务器有点麻烦,但我解决了。我撰写了一份步骤说明,介绍了我如何让postgres与rails配合工作,网址在这里:http://stackoverflow.com/questions/17971101/how-do-i-start-enterpisedb-postgresql-on-mac-osx-10-6-8/18007600#18007600 - 7stud
显示剩余2条评论

9

我刚刚在命令中加入了--password标志,按下回车后它要求我输入密码,我已经提供了。


1
对我来说很有效,只需在命令的末尾添加它并按回车键即可! - ruohola
1
有没有一种非交互式的方式可以通过命令行提供密码? - payne

7
psql -U postgres --password

Password:<Enter your password>

然后这个会出现:postgres=#

这对我有用。


4

如果没有提供数据库的密码,则会发生这种情况。

default="postgres://postgres:password@127.0.0.1:5432/DBname"


1
我的解决方法是确保在database.yml文件中,在开发、测试和生产之后有这四行代码。出于安全考虑,我在此处留空用户名和密码,但在实际应用程序中填写它们。
  username: 
  password: 
  host: localhost
  port: 5432

0

我也遇到了同样的问题。但是我的应用程序正在运行docker守护进程中。我在docker-compose.yml文件中更改了这些环境,并且还更改了database.yml文件。这些更改解决了我的问题。

 DATABASE_HOST= db
 POSTGRES_PASSWORD= password

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接