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.
Related
I'm trying to connect to a postgresql database which is in localhost:5432 but I keep getting the error:
FATAL: Ident authentication failed for user "".
I installed Postgres11 on virtual machine running Centos7. Created a database through command line, with the name business_db.
I've checked and postgresql is running in localhost:5432.
My pg_hba.conf file is like this:
# TYPE DATABASE USER ADDRESS METHOD
local all all peer
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
The pg_ident.conf file doesn't hold any configurations:
# Put your actual configuration here
# ----------------------------------
# MAPNAME SYSTEM-USERNAME PG-USERNAME
The database exists as shown by the command:
I'm logged into the system as "dev" user but., whatever I try while testing connection whit DBeaver, I allways get the error:
I also tried to set User as postgres and use my system password but get the same error. What am I missing?
When you use JDBC, you have to use password authentication. Neither ident nor peer will work for that.
You will need to add, e.g.:
host all all 127.0.0.1/32 md5
at the top of your pb_hba.conf
(replace md5 with scram-sha-256 if you are using that)
Change the ident to trust if you don't want to enter a password or to md5 if you want to enter a password.
Then reload the PostgreSQL server.
In (Ubuntu OS), change (or set) password in this way to solve this problem:
1- In terminal, run this command:
sudo -u postgres psql template1
2- Then run this command:
ALTER USER postgres with encrypted password 'your_password';
remove any spaces from your password, this worked for me
I'm pulling my hair out trying to figure out what is wrong.
I am attempting to connect to a local install of postgres 11 on ubuntu 19.
sudo -u postgres psql gives me full access to the psql shell as user postgres. I created a new user and db, granted permissions, set a password, edited the pg_hba.conf file, and restarted the server. I have also ensured that my password is not expired.
Now I expect psql "host=localhost user=marcos port=5433 dbname=reddit sslmode=require" to connect to my database, but I get a password error: "psql: FATAL: password authentication failed for user". I know the password I typed is correct, so what is wrong?
Here are the relevant pg_hba.conf lines:
# 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 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 all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
# custom rules
host all marcos all md5
follow this step for ubuntu/linxs
-> sudo -u postgres psql
-> postgres=#
After that right
->postgres=# \password
Enter new password for user “postgres”:
Enter it again:
Now check, the new password is working successfully.
Maybe something is wrong with your old password, try this:
ALTER ROLE marcos WITH ENCRYPTED PASSWORD '<new_password>';
And then connect to your DB with this password.
I just installed PostgreSQL 9.2 server on an EC2 AMI instance. However I am not able to connect to it from the command prompt.
Moreover I see two directories in /var/lib: pgsql9 and pgsql92. The data directory in pgsql92 is empty and hence it looks like pgsql9 is the one that is getting used.
[root#ip-172-31-56-103 etc]# psql
Password:
psql: FATAL: password authentication failed for user "root"
[root#ip-172-31-56-103 etc]# sudo su - postgres
-bash-4.2$ psql
Password:
psql: FATAL: password authentication failed for user "postgres"
-bash-4.2$ psql -U postgres
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
-bash-4.2$
pg_hba.conf
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
# 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
postgresql.conf
listen_addresses = '*'
To work out which PG install you are using: ps -ef | grep pgsql. You will see for sure which binary, data directory and conf file is being used to give you some comfort.
Have you changed the pg_hba.conf from the default? If so, did you reload it? Something like sudo service postgresql reload should do it, depending upon your OS.
You might want to change the IPv6 local connection to use md5 as well.
Try adding -h localhost or -h 127.0.0.1 to your psql command: e.g. psql -h localhost -U postgres.
Check your postgres password to be doubly / triply sure.
Otherwise, check out the specific docs for your OSs installation. Sometimes apt or yum repos do some additional security configuration for you.
Finally, worst case, change all the pg_hba.conf auth methods to trust, then restart the database, logon, change the postgres password, logout, change the auth methods to md5, reload and try to logon again.
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
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