Rails Connection PostgreSQL Error: Psql: Fatal error: User "Postgres" Ident authentication failed

Source: Internet
Author: User
Tags md5 postgresql psql postgres database postgresql client

Psql: Fatal error: User "Postgres" Ident authentication failed

1 after installing the PostgreSQL database, you need to initialize and some configuration rails project to connect PostgreSQL.


After the PostgreSQL data is installed (the Yum command is installed directly)

First step: Initialize the database

#service PostgreSQL Initdb

(Description: After initialization the default PostgreSQL database has a default user postgres (password is empty) and a default created Postgres database)

Step two: Start the database

#service PostgreSQL Start

If this command is not available, use: #systemctl start Postgresql.service

To start the database to modify the password condition

Step three: Switch user to change password

#su Postgres

#psql

#alter user postgres with password ' kuange ';

(Modify Postgres user password to Kuange, this password with your own modification)

# \q

Fourth step: Modify the Authentication file/var/lib/pgsql/data/pg_hba.conf, login using password.

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

The authentication method in this configuration file ident modified to trust, you can use the account and password to access the database,

That resolves psql: fatal error: User "Postgres" Ident authentication failed this issue)

Fifth step: Restart the PostgreSQL server for the settings to take effect

#service PostgreSQL Restart

Or

#systemctl Restart Postgresql.service

This solves the problem and the database can be accessed properly by the Rails project.



pg_hba.conf The complete code for this file is as follows:

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

# 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 is allowed to connect, how clients
# is 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 is 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 a 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 with 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
# 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 to an IP address and a CIDR mask
# an integer (between 0 and a (IPv4) or (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 a 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 is 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 is
# 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 was 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 and take effect. You can
# use ' Pg_ctl reload ' to ' do '.

# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "Host" records. In this case you'll 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 sockets connections only
Local all All trust
# IPV4 Local connections:
Host All 127.0.0.1/32 Trust
# IPV6 Local connections:
Host 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

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






Rails Connection PostgreSQL Error: Psql: Fatal error: User "Postgres" Ident authentication failed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.