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.

# Put your actual configuration here

# ----------------------------------

#

# If you want to allow non-local connections, you need to add more

# "host" records.  In that case you will also need to make PostgreSQL

# listen on a non-local interface via the listen_addresses

# configuration parameter, or via the -i or -h command line switches.

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only

local   all             all                                                  trust

# IPv4 local connections:

host    all             all             127.0.0.1/32            trust

# IPv6 local connections:

host    all             all             ::1/128                       trust

# Allow replication connections from localhost, by a user with the

# replication privilege.

#local   replication     postgres                                            peer

#host    replication     postgres        127.0.0.1/32             ident

#host    replication     postgres        ::1/128                        ident

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

时间: 2024-10-13 23:46:58

rails连接postgresql错误:psql: 致命错误: 用户 "postgres" Ident 认证失败的相关文章

PostgreSQL远程连接配置管理/账号密码分配(解决:致命错误: 用户 "postgres" Ident 认证失败)

问题:致命错误: 用户 "postgres" Ident 认证失败 说明:这个是由于没有配置远程访问且认证方式没改造成的,只需要更改使用账号密码认证即可. 解决:找到pg_hba.conf(find / -name pg_hba.conf),METHOD的ident修改为md5,且把ip端改为0.0.0.0/0,或者想要的IP地址即可.修改完成后直接reload即可. 特别吐槽:网上说直接trust,其实这个意思是只验证用户名,不验证密码!千万不要这样使用!!! METHOD指定如何处

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

psql: 致命错误:  用户 "***" Ident 认证失败 或 psql: FATAL: Ident authentication failed for user "username", mais pourquoi donc ? 解决办法:修改"pg_hba.conf"文件中认证方式"METHOD"为"md5"或"trust",具体参考文件中的说明. psql: 致命错误: 用户

psql: 致命错误: 用户 "ASUS" Password 认证失败

psql: 致命错误: 用户 "ASUS" Password 认证失败 如果发生这样的错误,意味着你的命令行少写了一个 -U psql -h localhost -U postgres -d "student" < "d:\student.sql" 原文地址:https://www.cnblogs.com/kmxojer/p/11700754.html

修改PostgreSQL数据库的默认用户postgres的密码

有时候,忘记了postgresql 安装时默认用户postgres 的密码,怎么办呢? linux shell命令下面输入: sudo -u postgres psql  (这样就可以直接登录进postgres 了, 然后在里面可以进行添加用户,修改密码之类的,都不是问题了!!) -------------------------------------------------------------------------------------------------------------

psql: 致命错误: 对用户&quot;user1&quot;的对等认证失败

操作系统:Debian8 登录pg时可能会有提示错误: $ psql -U user1 -d exampledb psql: 致命错误: 对用户"user1"的对等认证失败 打开以下文件, $ sudo vi /etc/postgresql/9.4/main/pg_hba.conf # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only loca

MySQL出现错误1045,用户无法连接

1.root用户可以登陆进去 sqlin用户为新建的无法连接MySQL的语句 root用户登录进去,重新修改该用户的密码,执行语句 use mysql: update user set password=password("sqlin") where user="sqlin(用户名)"; 此语句表示更改用户名为sqlin用户的密码,同时还进行了password()加密操作,一定不能直接 ` password="sqlin"`` 2.root用户登

PHP连接PostgreSQL连接问题

/var/lib/pgsql/data/pg_hba.conf CentOS 6.3下PostgreSQL 的安装与配置 http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html postgresAdmin3 http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html http://jingyan.baidu.com/article/3ea51489ec3cb452e

metasploit连接postgresql数据库

metasploit 连接postgresql数据库: 1.打开postgresql服务:services postgresql start 2.进入postgresql中,设置默认用户密码.创建新用户.设置新用户权限.创建数据库: sudo -u postgres psql#进入postgresql默认的用户 alter user postgres with password '密码'; #设置默认用户的登录密码 create user '用户名' wiht password '密码' noc

PHP连接PostgreSQL

yum install php-pgsql 在开始使用PHP PostgreSQL接口,打开pg_hba.conf文件(在PostgreSQL安装目录),并添加下面一行: # IPv4 local connections: host    all         all         127.0.0.1/32          md5 使用start/restart启动Postgres服务器,它没有运行使用下面的命令: [[email protected]]# service postgres