最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

Rails连接PostgreSQL错误:psql:致命错误:用户“postgres”Ident认证失败

来源:懂视网 责编:小采 时间:2020-11-09 12:51:56
文档

Rails连接PostgreSQL错误:psql:致命错误:用户“postgres”Ident认证失败

Rails连接PostgreSQL错误:psql:致命错误:用户postgresIdent认证失败:Rails连接PostgreSQL错误:psql: 致命错误: 用户 postgres Ident 认证失败 psql: 致命错误: 用户 postgres Ident 认证失败 1安装好postgresql数据库后需要初始化及一些配置rails项目才能连接postgresql 安装好postgresql数据后
推荐度:
导读Rails连接PostgreSQL错误:psql:致命错误:用户postgresIdent认证失败:Rails连接PostgreSQL错误:psql: 致命错误: 用户 postgres Ident 认证失败 psql: 致命错误: 用户 postgres Ident 认证失败 1安装好postgresql数据库后需要初始化及一些配置rails项目才能连接postgresql 安装好postgresql数据后

Rails连接PostgreSQL错误:psql: 致命错误: 用户 postgres Ident 认证失败

psql: 致命错误: 用户 "postgres" Ident 认证失败

1安装好postgresql数据库后需要初始化及一些配置rails项目才能连接postgresql

安装好postgresql数据后(yum命令直接安装的)

第一步:初始化数据库

#service postgresql initdb

(说明:初始化后默认postgresql数据库有一个默认的用户postgres(密码为空)和一个默认创建的postgres数据库)

第二步:启动数据库

#service postgresql start

如果这个命令不能使用请使用:#systemctl start postgresql.service

来启动数据库,,为修改密码条件


第三步:切换用户修改密码

#su postgres

#psql

#alter user postgres with password 'kuange' ;

(修改postgres用户密码为kuange,这个密码随你自己修改)

# \q

第四步:修改认证文件/var/lib/pgsql/data/pg_hba.conf,登陆使用密码。

#vi /var/lib/pgsql/data/pg_hba.conf


把这个配置文件中的认证 METHOD的ident修改为trust,可以实现用账户和密码来访问数据库,

即解决psql: 致命错误: 用户 "postgres" Ident 认证失败 这个问题)

第五步:重启postgresql服务器使设置生效

#service postgresql restart

或者

#systemctl restart postgresql.service


这样问题就解决了,数据库可以正常被rails项目访问了

pg_hba.conf这个文件的完整代码如下:

#=========================================

# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
#
# local DATABASE USER METHOD [OPTIONS]
# host DATABASE USER ADDRESS METHOD [OPTIONS]
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type: "local" is a Unix-domain
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
# plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, or a comma-separated list thereof. The "all"
# keyword does not match "replication". Access to replication
# must be enabled in a separate record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "@" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
# "krb5", "ident", "peer", "pam", "ldap", "radius" or "cert". Note that
# "password" sends passwords in clear text; "md5" is preferred since
# it sends encrypted passwords.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the postmaster receives
# a SIGHUP signal. If you edit the file on a running system, you have
# to SIGHUP the postmaster for the changes to take effect. You can
# use "pg_ctl reload" to do that.

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

Rails连接PostgreSQL错误:psql:致命错误:用户“postgres”Ident认证失败

Rails连接PostgreSQL错误:psql:致命错误:用户postgresIdent认证失败:Rails连接PostgreSQL错误:psql: 致命错误: 用户 postgres Ident 认证失败 psql: 致命错误: 用户 postgres Ident 认证失败 1安装好postgresql数据库后需要初始化及一些配置rails项目才能连接postgresql 安装好postgresql数据后
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top