ruby-on-rails - PostgreSQL 错误, "no pg_hba.conf entry"

标签 ruby-on-rails ruby postgresql heroku

我是编程新手。我正在构建一个 Rails 应用程序,现在想将它推送到 Heroku。我关注了Heroku's guidelines用于将我的数据库从 sqlite 3 转换为 postresql。这样做之后,当我尝试迁移或什至在本地主机上检查我的应用程序时出现此错误

“PG::ConnectionBad:致命:主机“[local]”、用户“keemtaker”、数据库“tuma_database_development”、SSL 关闭没有 pg_hba.conf 条目

我查看了以前对同一问题的回答,但它让我感到困惑和不知所措。如果我能获得解决此错误的分步指南,那就太好了。我以前使用过 PostgreSQL,没有任何问题。这就是我的 gemfile 的样子

    source 'https://rubygems.org'
ruby '2.3.4'

gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'puma'
gem 'rails', '5.1.4'
gem 'redis'
gem 'cloudinary'
gem 'carrierwave', '~> 1.2'
gem 'rails_admin', '~> 1.2'
gem 'pg'

gem 'autoprefixer-rails'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'font-awesome-sass'
gem 'sass-rails'
gem 'simple_form'
gem 'turbolinks', '~> 5.0.0'
gem 'coffee-rails'

gem 'uglifier'
gem 'webpacker'
gem 'devise'
gem 'ransack'
gem 'trix'


gem "letter_opener", group: :development


group :development do
  gem 'web-console', '>= 3.3.0'
end

group :development, :test do
  # gem 'binding_of_caller'
  # gem 'better_errors'

  gem 'pry-byebug'
  gem 'pry-rails'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

在我的 database.yml 中,我有

    default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: tuma_database_development

test:
  <<: *default
  database: tuma_database_test

production:
  <<: *default
  database: tuma_database_production

最佳答案

根据 Heroku Support这不是来自您的 Rails 应用程序的错误,而是来自试图对您的 PostgreSQL 数据库进行身份验证的恶意人员:

Issue

I'm seeing failed connection attempts in my Heroku Postgres logs, but I'm not creating these connections and they come from an IP address that I don't recognize. It looks like someone might be trying to hack my database:

sql_error_code = 28000 FATAL: no pg_hba.conf entry for host "122.180.247.11", user "postgres", database "postgres", SSL off

Variations of the above error might include the user being set to root, admin, test, or other default usernames.

Resolution

These errors indicate a failed login attempt was made to your database, which means that the connection wasn't established.

It is common to see failed connection attempts that use default usernames (such as user "postgres", database "postgres"). Being on the public internet means some level of unauthorized access attempts are possible. These are very unsophisticated attempts that usually involve trying combinations like root, psql, test and postgres. However, Heroku Postgres usernames, passwords, and database name combinations are randomly generated, making these generic access attempts futile.

Another common cause of the sql_error_code=28000, particularly when it involves the "unsupported frontend protocol" message is the use of tools like nmap. Read more about the "unsupported frontend protocol" message.

Heroku takes security seriously and works diligently to ensure the safety of your data. Furthermore, trust is a core principle of salesforce.com and Heroku. It’s this commitment to customer privacy and inspiring trust that directs the decisions we make on a daily basis. Trust is the responsibility of each and every employee and one we take seriously.

关于ruby-on-rails - PostgreSQL 错误, "no pg_hba.conf entry",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49086043/

相关文章:

postgresql - 将日志文件中的行号与函数代码匹配

sql - postgresQL 中的参数可以使用 "?"吗?

ruby-on-rails - 具有未知键和强参数的 Rails 哈希

ruby - 将诱惑报告结果发送到 aws s3

ruby - 是否有可能让 Rubygems 与 Ruby 1.8.3 一起工作?

ruby-on-rails - ruby rails : making id in column as an alias?

postgresql - docker : "could not open output file" "protocol error" 中的 pg_dump

ruby-on-rails - 在 Ruby on Rails 3.2 应用程序中集成 googlefonts

ruby-on-rails - 查找具有特定帖子的所有男性用户

mysql - Rails 2.2 中的脚手架?