的对等身份验证失败在轨道上的红宝石

的对等身份验证失败在轨道上的红宝石

本文介绍了遇到致命故障:用户“ postgres”的对等身份验证失败在轨道上的红宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使其与Postgresql 11配合使用时,我遇到了Rails 5.2.3的问题。

  FATAL:用户 postgres的对等身份验证失败

我一直在检查和



他们谈论 pg_hba.conf ,以及如何将方法更改为md5或trust。我的硬盘上没有这样的文件。这些归档文件位于 / var / lib / postgresql / 11 / 中:

  base pg_dynshmem pg_notify pg_snapshots pg_subtrans PG_VERSION postgresql.auto.conf 
全局pg_logical pg_replslot pg_stat pg_tblspc pg_wal postmaster.opts
pg_commit_ts pg_multixact pg_serial pg_stat_tmp pg_twophase pg_x $$$$

如果我尝试找到该文件,它将显示在这里:

  $ locate pg_hba.conf 
/home/linuxbrew/.linuxbrew/var/postgres/pg_hba.conf

如果我走进去,则已经使用了trust方法。



我已经卸载了postgresql和。



这是我的database.yml文件:

 #PostgreSQL。支持9.1及更高版本。 

#安装pg驱动程序:
#gem install pg
#在OS X上使用Homebrew:
#gem install pg---with-pg- config = / usr / local / bin / pg_config
#在带有MacPorts的OS X上:
#gem install pg---with-pg-config = / opt / local / lib / postgresql84 / bin / pg_config
#在Windows上:
#gem install pg
#选择win32版本。
#安装PostgreSQL并将其/ bin目录放在您的路径上。

#使用Gemfile配置
#gem'pg'

默认值:& default
适配器:postgresql
编码:unicode
#有关连接池的详细信息,请参见Rails配置指南
#http://guides.rubyonrails.org/configuring.html#database-pooling
池:<%= ENV.fetch ( RAILS_MAX_THREADS){5}%>

开发:
<< ;: *默认
数据库:postgres
用户名:postgres
#host:localhost
池:< ;%= ENV.fetch( RAILS_MAX_THREADS){5}%>
#用于连接到postgres的指定数据库角色。
#要在postgres中创建其他角色,请参见`$ createuser --help`。
#留空时,postgres将使用默认角色。这是
#与初始化数据库的操作系统用户相同的名称。

#与postgres角色(用户名)相关的密码。

#在TCP套接字上连接。默认情况下省略,因为客户端使用不需要配置的
#域套接字。 Windows没有
#域套接字,因此请取消注释这些行。
#主机:localhost

#服务器侦听的TCP端口。默认值为5432。
#如果您的服务器在其他端口号上运行,请进行相应的更改。
#端口:5432

#架构搜索路径。服务器默认为$ user,public
#schema_search_path:myapp,sharedapp,public

#最小日志级别,以递增顺序:
#debug5,debug4,debug3,debug2, debug1,
#日志,通知,警告,错误,致命和紧急
#默认为警告。
#min_messages:通知

#警告:当您运行 rake时,定义为 test的数据库将被删除,并从开发数据库中重新生成
#。
#请勿将此数据库设置为与开发或生产相同的数据库。
测试:
< :: *默认
数据库:postgres
用户名:postgres
主机:localhost
池:5




#与config / secrets.yml一样,您永远都不想在源代码中存储敏感信息,例如数据库密码,
#。如果您的源代码是任何人都曾经看过的
#,那么他们现在就可以访问您的数据库。

#而是在启动
#应用程序时提供密码作为Unix环境变量。请阅读http://guides.rubyonrails.org/configuring.html#configuring-a-database
#,以获取有关如何在
#生产部署中提供这些环境变量的完整摘要。

#在Heroku和其他平台提供商上,您可能具有完整的连接URL
#作为环境变量。例如:

#DATABASE_URL = postgres:// myuser:mypass @ localhost / somedatabase

#您可以使用此数据库配置:

#生产:
#网址:<%= ENV ['DATABASE_URL']%>

生产:
<< ;: *默认
数据库:postgres
用户名:postgres

如果我删除行

 用户名:postgres 

我得到

 致命:角色根不存在


解决方案

我昨天遇到了这个问题。试试这个...
这应该做

 默认值:& default 
适配器:postgresql
池:5
主机:localhost

开发:
<< ;: *默认
数据库:prj_development
用户名:pg_username
密码:pg_password

我在使它起作用时唯一注意到的区别是主机

 主机:localhost 

为了确保我只注释了键 host 并重现了以下错误


I am running into this problem with rails 5.2.3 when trying to make it work with postgresql 11.

FATAL: Peer authentication failed for user "postgres"

I have been checking 1 and 2

They talk about pg_hba.conf and how the methods should be changed to md5 or trust. In my hard disk, there is no such file. These archives are found within /var/lib/postgresql/11/ :

base          pg_dynshmem   pg_notify    pg_snapshots  pg_subtrans  PG_VERSION  postgresql.auto.conf
global        pg_logical    pg_replslot  pg_stat       pg_tblspc    pg_wal  postmaster.opts
pg_commit_ts  pg_multixact  pg_serial    pg_stat_tmp   pg_twophase  pg_xact postmaster.pid

If I try to locate the file it will appear here:

$locate pg_hba.conf
/home/linuxbrew/.linuxbrew/var/postgres/pg_hba.conf

If I go inside, the method trust is already used.

I have already uninstalled postgresql and install it again.

This is my database.yml file:

# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: postgres
  username: postgres
  #host: localhost
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  # 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.

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

  # 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

# 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: postgres
  username: postgres
  host: localhost
  pool: 5




# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  database: postgres
  username: postgres

If I remove the line

  username: postgres

I get

FATAL: role "root" does not exist
解决方案

I had faced this issue yesterday. Try this ...This should do

default: &default
  adapter: postgresql
  pool: 5
  host: localhost

development:
  <<: *default
  database: prj_development
  username: pg_username
  password: pg_password

The only difference I noticed while making it work was the host key

host: localhost

To make sure I just commented the key host and reproduced the following error

这篇关于遇到致命故障:用户“ postgres”的对等身份验证失败在轨道上的红宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:16