Rails connection postgresql error: psql: Fatal error: user & quot; postgres & quot; Ident authentication failed, psqlpostgres

Source: Internet
Author: User
Tags psql unix domain socket postgres database postgresql client

Rails connection postgresql error: psql: Fatal error: User "s" Ident authentication failed, psqlpostgres
Psql: Fatal error: User "s" Ident authentication failed

1. After the postgresql database is installed, you must initialize and configure some rails projects to connect to postgresql.


After postgresql data is installed (the yum command is directly installed)

Step 1: Initialize the database

# Service postgresql initdb

(Note: After initialization, the default postgresql database has a default user named S (the password is blank) and a default created postgres database)

Step 2: Start the database

# Service postgresql start

If this command cannot be used, use: # systemctl start postgresql. service

To start the database.

Step 3: Change the user's password

# Su ipvs

# Psql

# Alter user Login s with password 'kuange ';

(Change the postgres user password to kuange. You can change this password as needed)

# \ Q

Step 4: Modify the authentication file/var/lib/pgsql/data/pg_hba.conf and log on to the system using the password.

# Vi/var/lib/pgsql/data/pg_assist.conf

You can change the ident of the authentication METHOD in this configuration file to trust to access the database using the account and password,

That is to solve the problem of psql: Fatal error: User "s" Ident authentication failure)

Step 5: restart the postgresql server to make the settings take effect.

# Service postgresql restart

Or

# Systemctl restart postgresql. service

The problem is solved, and the database can be normally accessed by the rails project.



The complete code for the pg_cmd.conf 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 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
# Plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", "replication",
# 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
# 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
# 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) hybrid) 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.
#
# 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
# That name.
#
# This file is read on server startup and when the postmaster has es
# 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 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
# Replication privilege.
# Local replication ipvs peer
# Host replication ipvs 127.0.0.1/32 ident
# Host replication slave S: 1/128 ident

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







Postgres database connection problems

Which file is configured? s rejects access to the local database by default. One configuration file is "pg_hba.conf" to add a row.
"Host all 192.168.0.0/16 trust"
This function is accessible from ip addresses starting with 192.168. authentication is not required when the trust settings are fully enabled.

PostgreSQL: SQL Exception :???????? :???? "Root "??????

Root is also your postgresql user. log on to postgresql and try postgres by default.

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.