95

数据库.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
4

6 回答 6

77

pg_hba.conf对or文件进行更改后postgresql.conf,需要重新加载集群以获取更改。

从命令行:pg_ctl reload

从数据库中(作为超级用户):select pg_reload_conf();

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

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

于 2013-08-01T14:56:58.037 回答
7

我只是将--password标志放入我的命令中,然后按 Enter 后它要求我输入密码,这是我提供的。

于 2019-11-15T17:10:01.383 回答
3
psql -U postgres --password

Password:<Enter your password>

然后就会出现这个。 postgres=#

这对我有用

于 2021-05-12T06:58:34.420 回答
2

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

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

于 2020-03-12T09:11:08.337 回答
0

我也有同样的问题。但是我的应用程序在 docker daemon 上运行。docker-compose.yml我在文件中更改了那些环境。database.yml并且在文件中也发生了变化。这些更改解决了我的问题。

 DATABASE_HOST= db
 POSTGRES_PASSWORD= password
于 2021-12-02T21:04:40.257 回答
-2

不要使用密码。改用对等身份验证

postgres://myuser@%2Fvar%2Frun%2Fpostgresql/mydb
于 2021-01-31T11:29:42.057 回答