我在SQlite和MySQL上使用过rails。第一次使用PostgreSQL。刚刚在我的本地机器上安装了PostgreSQL。使用Heroku进行制作。
每次我运行rake db:migrate 或 rake db:create 我都会收到以下错误:
PG::ConnectionBad: fe_sendauth: no password supplied
我用Homebrew安装了PostgreSQL,但从未设置用户或密码。 这是我的Postgres设置:
Daves-MBP-2:project dave$ ps aux | grep postgres
postgres 670 0.0 0.0 2466764 1816 ?? S Fri10AM 0:00.33 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdflagwriter
postgres 658 0.0 0.0 2514516 3032 ?? S Fri10AM 0:01.31 /usr/sbin/distnoted agent
postgres 657 0.0 0.0 2542724 6336 ?? S Fri10AM 0:05.69 /usr/libexec/trustd --agent
postgres 656 0.0 0.0 2545304 6676 ?? S Fri10AM 0:04.28 /usr/libexec/lsd
postgres 655 0.0 0.0 2515008 2596 ?? S Fri10AM 0:00.07 /usr/sbin/cfprefsd agent
postgres 240 0.0 0.0 2508940 920 ?? Ss Fri10AM 0:01.06 postgres: stats collector process
postgres 239 0.0 0.0 2653940 1860 ?? Ss Fri10AM 0:00.64 postgres: autovacuum launcher process
postgres 238 0.0 0.0 2653940 832 ?? Ss Fri10AM 0:01.00 postgres: wal writer process
postgres 237 0.0 0.0 2653940 900 ?? Ss Fri10AM 0:01.02 postgres: writer process
postgres 236 0.0 0.0 2653940 896 ?? Ss Fri10AM 0:00.04 postgres: checkpointer process
postgres 233 0.0 0.0 2508940 728 ?? Ss Fri10AM 0:00.00 postgres: logger process
postgres 108 0.0 0.0 2654196 3372 ?? Ss Fri10AM 0:00.32 /Library/PostgreSQL/9.6/bin/postmaster -D/Library/PostgreSQL/9.6/data
dave 68244 0.0 0.0 2442020 2012 s000 S+ 4:28PM 0:00.00 grep postgres
这是我的database.yml文件
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
adapter: postgresql
encoding: unicode
database: "mydatabase"
# 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:
<<: *default
database: db/test.sqlite3
production:
adapter: postgresql
encoding: unicode
url: "HEROKU URL"
以下是我从中获取的pg_hba.conf的设置 - cd / usr / local / var / postgres / - 打开pg_hba.conf
我错过了什么?
由于
修改
以下评论的内容如下:
第一个文件“com.edb.launchd.postgresql-9.6.plist”:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.edb.launchd.postgresql-9.6</string>
<key>ProgramArguments</key>
<array>
<string>/Library/PostgreSQL/9.6/bin/postmaster</string>
<string>-D/Library/PostgreSQL/9.6/data</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>postgres</string>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
</dict>
</plist>
第二个文件“homebrew.mxcl.postgresql.plist”:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.postgresql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/postgresql/bin/postgres</string>
<string>-D</string>
<string>/usr/local/var/postgres</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/postgres.log</string>
</dict>
</plist>
答案 0 :(得分:0)
在编辑器中打开文件/Library/PostgreSQL/9.6/data/pg_hba.conf
。确保USER和METHOD的值匹配以下示例(所有和信任)。
# 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
保存文件,然后从终端运行pg_ctl reload -D /Library/PostgreSQL/9.6/data
。