2016-09-07 35 views
0

我正在用Postgres數據庫建立一個使用Rails 5.0.0的應用程序。Postgres SQL密碼的Rails 5問題

當我嘗試運行任何耙命令,我收到以下錯誤:

rake aborted! 
PG::ConnectionBad: fe_sendauth: no password supplied} 

我找遍了整個堆棧溢出無濟於事上固定的問題。

這裏是我的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  John        trust 
#host replication  John  127.0.0.1/32   trust 
#host replication  John  ::1/128     trust 

這裏是我的發展database.yml文件:

development: 
<<: *default 
database: in-the-paint_development 

# The specified database role being used to connect to postgres. 
# To create additional roles in postgres see `$ createuser --help`. 
# When left blank, postgres will use the default role. This is 
# the same name as the operating system user that initialized the database. 
# username: in-the-paint 

# The password associated with the postgres role (username). 
# password: 

# Connect on a TCP socket. Omitted by default since the client uses a 
# domain socket that doesn't need configuration. Windows does not have 
# domain sockets, so uncomment these lines. 
# host: localhost 

# The TCP port the server listens on. Defaults to 5432. 
# If your server runs on a different port number, change accordingly. 
# port: 5432 

# Schema search path. The server defaults to $user,public 
#schema_search_path: myapp,sharedapp,public 

# Minimum log levels, in increasing order: 
# debug5, debug4, debug3, debug2, debug1, 
# log, notice, warning, error, fatal, and panic 
# Defaults to warning. 
#min_messages: notice 

最後,我用下面的命令來安裝的Postgres:

brew install postgres 
mkdir -p $HOME/Library/LaunchAgents 
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 

最大的問題是我在設置Postgres時從未提示過提供密碼,所以我確實不知道我的database.yml中提供了什麼。留下空白(「」)空間不能解決問題。

您是否知道我可以在此代碼中提供的任何內容或可以運行的命令幫助解決此問題?

+2

啓動psql的會話,並檢查pg_users表,看看你有什麼用戶。如果我記得,按照您所做的方式安裝PG不會創建您的應用所期望的默認postgres用戶。 – MarsAtomic

+0

添加密碼在數據庫yml中 –

回答

0

這就是我所做的。 1)在pgsql中創建一個新用戶,給他一個密碼,創建一個與用戶名相同的數據庫,給予用戶創建新數據庫的權限。 2)然後在database.yml文件

development: 
    <<: *default 
    database: appname_development #this will come by default if you specify to pg while creating app 
    username: user 
    password: password 
    pool: 5 
    host: localhost