简体   繁体   English

将密码存储在 Rails 中的 ENV 变量中时收到“PG::ConnectionBad fe_sendauth:未提供密码”错误

[英]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.

相关问题 PG :: ConnectionBad fe_sendauth:未提供密码 - PG::ConnectionBad fe_sendauth: no password supplied PG::ConnectionBad: fe_sendauth: 未提供密码 - PG::ConnectionBad: fe_sendauth: no password supplied Rails / PostgreSQL问题:PG :: ConnectionBad:fe_sendauth:未提供密码 - Rails/PostgreSQL problem: PG::ConnectionBad: fe_sendauth: no password supplied capistrano,rails,PG :: ConnectionBad:fe_sendauth:没有提供密码 - capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied Rails 控制台导致 PG::ConnectionBad: fe_sendauth: 没有提供密码 - Rails Console results in PG::ConnectionBad: fe_sendauth: no password supplied Rails Postgres Github 操作错误:PG::ConnectionBad:fe_sendauth:未提供密码 - Rails Postgres Github Actions error: PG::ConnectionBad: fe_sendauth: no password supplied 耙终止:PG :: ConnectionBad:fe_sendauth:未提供密码 - rake aborted:PG::ConnectionBad: fe_sendauth: no password supplied 修复方法:PG :: ConnectionBad:fe_sendauth:未提供密码 - how to fix: PG::ConnectionBad: fe_sendauth: no password supplied &#39;initialize&#39;:fe_sendauth:不提供密码(PG :: ConnectionBad) - `initialize': fe_sendauth: no password supplied (PG::ConnectionBad) 耙子流产了! PG :: ConnectionBad:fe_sendauth:没有提供密码 - rake aborted! PG::ConnectionBad: fe_sendauth: no password supplied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM