[英]receiving “PG::ConnectionBad fe_sendauth: no password supplied” error when storing passwords in ENV variables in rails
I recently switched db's from sqlite3 to PG.我最近将 db 从 sqlite3 切换到 PG。 My username and password for pg were hard-coded, and although it was working, this was not safe practice.
我的 pg 用户名和密码是硬编码的,虽然它可以工作,但这不是安全的做法。 SO I stored my password in an ENV variable in a.yml file, and I reference that variable in my database.yml file, but when I run the server, it gives me the error "PG::ConnectionBad fe_sendauth: no password supplied"
所以我将密码存储在 a.yml 文件中的 ENV 变量中,并在我的 database.yml 文件中引用该变量,但是当我运行服务器时,它给了我错误“PG::ConnectionBad fe_sendauth:未提供密码”
the following is my pg_keys.yml file以下是我的 pg_keys.yml 文件
PG_PASSWORD: "***********"
And the following is my database.yml file:以下是我的 database.yml 文件:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: stockapp_development
username: postgres
password: <%= ENV['PG_PASSWORD'] %>
host: localhost
# 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: stockapp_test
host: localhost
username: postgres
password: <%= ENV['PG_PASSWORD'] %>
production:
<<: *default
database: stockapp_production
username: stockapp
password: <%= ENV['STOCKAPP_DATABASE_PASSWORD'] %>
Why is it saying that no password is supplied?为什么说没有提供密码? Does my database.yml not see the password in the other file?
我的 database.yml 没有在其他文件中看到密码吗? Do I need to export the password?
我需要导出密码吗?
It is because ENV
variables come from https://github.com/bkeepers/dotenv .这是因为
ENV
变量来自https://github.com/bkeepers/dotenv 。
Install this gem by adding it to your Gemfile
, then run bundle
and set the variable PG_PASSWORD=***********
in .env
in your root.通过将它添加到您的
Gemfile
来安装此 gem,然后运行bundle
并在根目录下的.env
中设置变量PG_PASSWORD=***********
。 Then it should work fine.然后它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.