I am trying to execute the following on a fresh Postgre started as a service on CentOS 7
psql -h localhost -p 5432 -U postgres -X -d postgres -f /home/user/Documents/test.sql
however i get this error :
psql: FATAL: Ident authentication failed for user "postgres"
my pg_hba.conf is defined as following:
# TYPE DATABASE USER ADDRESS METHOD
#remove-line-for-nolocal## "local" is for Unix domain socket connections only
#remove-line-for-nolocal#local all all #authmethodlocal#
# IPv4 local connections:
local all user peer
local all postgres 127.0.0.1/32 trust
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#remove-line-for-nolocal#local replication all #authmethodlocal#
host replication all 127.0.0.1/32 #authmethodhost#
host replication all ::1/128 #authmethodhost#
Why does the execution fail ?
Related
I'm trying to log in to a database with this command:
psql -U user my_db
This is the error that gets thrown:
psql: FATAL: Peer authentication failed for user "user"
I figured it had something to do with my pg_hba.conf. I tried several things but couldn't get it to work. This is the relevant part of pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local my_db user md5
local all all md5
# IPv4 local connections:
host my_db user 127.0.0.1/32 md5
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
I also get the same error when I first do su - postgres
and the try psql -U user
Edit: Turns out I was modifying the wrong pg_hba.conf. I solved the original problem, now I can log in like this: psql -U user my_db. But my application, which is running on the same device can't access the database with this pg_hba.conf. Checking the logs this is the line that shows up when my application makes new requests:
2019-12-10 16:18:51.144 +03 [29570] LOG: invalid length of startup packet
I'm trying to connect to psql console with psql -U postgres but keep getting the following Error:
psql: FATAL: Peer authentication failed for user "postgres"
This if the content on pg_hba.conf
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
I am trying to setup Icinga 2 on CentOS7 and followed instructions as mentioned in the official document. [https://docs.icinga.com/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/getting-started][1].I have created the database and user as icinga. I am facing the following issue psql: FATAL: password authentication failed for user "icinga" when trying to import the Icinga 2 IDO schema using the below commands
export PGPASSWORD=icinga and psql -U icinga -d icinga < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql
Below is my pg_hba.conf am using
# TYPE DATABASE USER ADDRESS METHOD
# icinga
local icinga icinga md5
host icinga icinga 127.0.0.1/32 md5
host icinga icinga ::1/128 md5
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# 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
Try to change
local all all peer
to:
local all all md5
Had this same issue on Ubuntu Bionic, was able to resolve by adding localhost explicitly as the host:
export PGPASSWORD=icinga
psql -U icinga -d icinga -h localhost < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql
I am trying to setup pgAdmin on a new macbook. I am in the process of setting up a local server but keep getting the error:
Error connecting to the server: FATAL: role "postgres" does not exist
Here are my settings:
And here are the contents of my pg_hba.conf file:
# 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 abc1234 trust
#host replication abc1234 127.0.0.1/32 trust
#host replication abc1234 ::1/128 trust
host all all localhost trust
host all all 192.168.1.0/24 trust
Can someone help?
Thanks in advance!
This error message is telling you that the postgres role, which is the usual "superuser" in a postgresql installation, does not exist.
In this case, it seems that the cluster has been installed using a local user as the superuser:
$ ls -ld /usr/local/var/postgres
drwx------ 30 abc1234 admin 1020 May 29 20:46 /usr/local/var/postgres
In which case we can probably login using:
$ psql -U abc1234 postgres
I am able to connect via command line but getting the usual error message in pgadmin3.
Error connecting to the server: FATAL: password authentication failed for user "postgres"
(and login failed in phppgadmin)
I know there are several q/a about this but none is addressing command-line success / pgadmin3 failure.
I have made the suggested changes such as:
adding listen_addresses = '*' in postgresql.conf
as also modifying trailing lines of pg_hba.conf as follows (to switch from peer to md5):
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
# host replication postgres ::1/128 md5
what is more, connection in the following way fails:
psql -h localhost -U postgres -d postgres
(password failure)
however, connection like this succeeds:
sudo -u postgres psql
Password: ****
It turns out that the server was listening to 5433 and both GUIs were trying to connect to 5432... the error message
password authentication failed
was very misleading though....