pgadmin3 server connection and authentication error - postgresql

I have recently installed postgresql 9.1 and pgadmin3. But I can't connect to server which I created with this config:
name: mydb
host: 127.0.0.1
port: 5432
service:
Maintenance DB: postgres
username: postgres
password: *
According to similar problems I've set my /etc/postgresql/9.1/main/pg_hba.conf file under ubuntu 12.04 LTS like this:
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "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
host all all localhost trust
But when I want to connect to the server I get this error:
Error connecting to the server: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"

That was simple after installation of postgresql i should change the postgres user password
and my failure was because of that. The password can simply change through this commands under ubuntu 12.04 LTS:
sudo -u postgres psql
And then in psql:
\password
Now enter the new password and re-enter it.
That's OK! then you can simply sign in.
This way there is no need to change the configuration of pg_hba.conf file.
In fact i failed to login because of my invalid password!

Seems your DB is configured for "postgres" user and PgAdmin is trying to connect as "postgre" (without s in the end).

Related

psql: error: FATAL: password authentication failed for user "user" on remote login

I'm trying to log in by passing the host's IP as a parameter, simulating a login from outside:
root#ubuntu-2gb-nbg1-1:/etc/postgresql/12/main# psql -h YYY.YYY.YYY.YYY -p 5433 -d myproject -U myproject
Password for user myproject:
psql: error: FATAL: password authentication failed for user "myproject"
FATAL: password authentication failed for user "myproject"
I then try to log in from the same host with the same password but with different options:
root#ubuntu-2gb-nbg1-1:/etc/postgresql/12/main# psql -h localhost -U myproject -d myproject
Password for user myproject:
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1), server 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
myproject=>
I am using PostgreSQL 12 and trying to set up a remote login for a service which should write to the DB from the outside. I've already set up the listener in /etc/postgresql/12/main/postgresql.conf to also listen to my remote server and configured my /etc/postgresql/12/main/pg_hba.conf as follows:
# Database administrative login by Unix domain socket
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
host all all XXX.XXX.XXX.XXX/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
The problem I have is that when attempting to log in remotely, the password authentication fails. The same username and password is correct when logging in from within the host. It's very strange that the password is being rejected when attempting the remote login. Does anyone have any suggestions?
Laurenz Albe's comment actually led me to the solution. It turned out I was running two different instances of PostgreSQL and didn't notice. The one I connected to over localhost was postresql-10 and had the proper user and database and the one I had configured to listen to the outside over port 5433 was postgresql-12 and didn't have the same users and databases.
In the end it was a simple fix to remove one instance and set up everything on the single version 12.

Postgres asking for forgotten password (MacOS)

I'm completely unable to access anything in postgres as it's asking for a password for both the default postgres user as well as my mac username. I don't have a password for either, and in the case of postgres I don't even understand why there is a password as by defualt it shouldn't have one.
After running through many other answers on the subject:
If I run psql:
$ psql
Password for user <MY_USERNAME>:
psql: error: could not connect to server: FATAL: password authentication failed for user "<MY_USERNAME>"
If I run it with sudo:
$ sudo psql
Password for user root:
psql: error: could not connect to server: FATAL: password authentication failed for user "root"
If I run it with postgres user:
$ sudo -u postgres psql
Password for user postgres:
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
Also in my pg_hba.conf all the methods are set to trust, have also tried changing to ident and md5.
On the advice of #jjanes I searched for other pg_hba.conf files and this is what I found:
/usr/local/var/postgres.old/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf
/usr/local/var/postgresql#10/pg_hba.conf
/Library/PostgreSQL/12/data/pg_hba.conf
The last one is empty (and read only) and the other three all look like this:
# 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 all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
Anyone have any advice?
I had a similar issue on my Ubuntu 21.10.
I also tried resolving the problem by following the steps suggested above, but none worked.
At last, I resolved the problem by uninstalling postgres and removing every related files: https://askubuntu.com/questions/32730/how-to-remove-postgres-from-my-installation/32735#32735
Thereafter, I did a new installation of postgres using: https://levelup.gitconnected.com/installing-and-configuring-postgresql-on-ubuntu-20-04-e50122635927
Now, everything works fine.
Cheers.

Failed Password Authentication for user 'postgres' on mac

I recently downloaded the graphical install for postgresql 9.4 on my mac and went through the entire setup, even made a password, but when it came to activate the shell no password would work. I tried my system password and the one I set but neither worked.
Everytime I try
sudo -u postgres psql
I get the error
psql: FATAL: password authentication failed for user "postgres"
This is my pg_hba.conf file
TYPE DATABASE USER ADDRESS METHOD
"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 md5
host replication postgres 127.0.0.1/32 md5
Try changing your psql password
Change local in conf file to: local all all trust
Restart psql server: sudo /etc/init.d/postgresql restart
Connect as superuser postgres: sudo -u postgres psql
Change password: ALTER USER postgres PASSWORD 'newpassword';
Change back your conf file to:
local all all md5
Restart psql server: sudo /etc/init.d/postgresql restart

PostgreSQL: MD5 Authentication in pg_hba.conf gives me FATAL: Peer authentication failed for user "postgres"

I'm running Ubuntu 14.04 and installed PostgreSQL 9.3.
Edited /etc/postgresql/9.3/main/pg_hba.conf as:
# "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
I restarted the server and now I'd like to login into postgres as postgres:
victor#workstation:~$ psql -U postgres
psql: FATAL: Peer authentication failed for user "postgres"
Shouldn't postgres prompt for my password, as I've set its authentication method to MD5 ?
I understand that if I add -h localhost it will work.
Does not adding this flag causes psql to use peer-authentication?
You must have another local ... peer line above those. The error Peer authentication failed comes from the server, and it's the server tha that picks the auth method.
Other possibilities would be:
Didn't actually restart the server
Edited the wrong pg_hba.conf file if there are multiple PostgreSQL instances on the system.
1) Open -> /etc/phppgadmin -> config.inc.php from your Terminal.
2) Find Below Line and Change it to False.
$conf['extra_login_security'] = true; to $conf['extra_login_security'] = false;
3) After changing Restart your Server.it will resolve your issue.
/etc/init.d/httpd restart

Postgres password authentication issue

I've installed PostgreSQL 9.1 and pgadmin3 on Ubuntu Server 13.10.
I configured postgresql.conf with: listen_addresses = '*'
also I configured ph_hba.conf by changed peer connections to md5
Plus I reset the password of postgres by: sudo password postgres
then restarted the service with sudo /etc/init.d/postgresql restart
after that I tried to connect to the default PostgreSQL template database:
sudo -u postgres psql template1
but login failed with this error message:
psql: FATAL: password authentication failed for user "postgres"
then I tried to login from the pgadmin, which gave me the same error.
I've read here that it might be a password expiry dates bug
PostgreSQL user can not connect to server after changing password
but I couldn't solve it coz I cannot login with psql. Does anyone now how to resolve this issue?
EDIT
ph_hba file:
local all postgres md5
local all all md5
local all all trust
host all all 127.0.0.1/32 md5
hostssl all all 192.168.0.0/16 trust
host all all 192.168.0.0/16 trust
host all all ::1/128 md5
in your pg_hba.conf, modify
local all postgres md5
to
local all postgres trust
then you'll be able to login without password