Postgresql - Password authentication failed [duplicate] - postgresql

I'm a noob in PostgreSQL. I installed ver 9.2 on windows7. During installation it asked for password and i entered it.
Now whenever i run d:\tools\PostgreSQL9.2\bin\psql.exe it asks for password. When i enter the password it doesn't accept and
it shows "password authentication failed for user "user1". I have re-installed twice already. Also i tried entering my system
password.
I'm trying to get the below command to work
psql.exe -f db/codedb.sql development
What should i do to get this working ?

Try setting the user name when connecting.
psql.exe -U username -d dbname -f somefile.sql
You've probably set up the default "postgres" user during installation. Not sure if you've created any others.
To add other users and databases just connect to as postgres to the postgres database and do something like:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;
If your machine is secure you might also like to set up a password file

change "trust" instead of "md5" in the pg_hba.conf to connect to the database and change your password.
--------------------configuration in pg_hba.conf---------------
local all all trust
local all postgres trust
host all all ::1/128 trust

Here is the simple solution for installation Postgresql without getting errors(cluster errors and authentication errors),i have followed below steps and i got installed postgresql sucessfully
create new user in windows from controlpanel-->user accounts
After logged into new user(whic u hve created) copy postrgresql(.exe) application into any directory(other than 'C') and click on the application to install(dont forget to change the installation directory to which u have copied the application file above).
after completion of installaion change below configurations in postgresql.conf and pg_hba.cof
add like below in your postgresql.conf
listen_addresses = '*'
add like below in your pg_hba.cof
# 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.
# host sameuser postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 md5

Related

How to force using password

I have just installed PostgreSQL on my Mac After the installation I logged in via:
$ psql postgres
At the next step I created new database:
CREATE DATABASE sample_db;
And now I added a user and grant it access to created DB:
CREATE USER sample_user WITH PASSWORD 'sample_pass';
GRANT ALL PRIVILEGES ON DATABASE sample_db TO sample_user;
When I log in with user, I do not need to enter the password:
psql sample_db -U sample_user
even, if I provide the -W option.
Also, if I try to log in with this user via some SQL-GUI such a tableplus.
How can I configure postgresql to force user using their password?
I modified the pg_hba.conf file to looking like this:
host sample_db sample_user 127.0.0.1/32 password
My intention or my guess was that psql will use it. But somehow it doesn't.
I also checked How to Force Postgresql User Login with Password, but with no positive effect to my issue.
pg_hba.conf
local all admin trust
local all all md5
host all admin 127.0.0.1/32 trust
host all all 127.0.0.1/32 md5
host all admin ::1/128 trust
host all all ::1/128 md5
I have a solution
The thing is that while you installing postgresql via brew there will be two pathes, where pg_hba.conf can potentially exist.
Wrong path: /opt/homebrew/opt/postgresql#15/share/postgresql#15/pg_hba.conf
Screen: inactive pg_hba path
Right path: /opt/homebrew/var/postgresql#15/pg_hba.conf
Screen: active pg_hba path
You can find the path of your pg_hba.conf inside pg_settings table. Just run
select * from pg_settings;
-
select setting from pg_settings where name = 'hba_file';
After placement of needed configuration and postgresql server restart, everything works like expected.

Cannot connect to local postgresql DB using DBeaver

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

psql: FATAL: password authentication failed for user {user}

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.

Postgres server password reset not working

I have Postgresql server 8.2 running on a Windows server. I am trying to reset the root postgres account password and just not having any luck. I have so far done the following:
Edited pg_hba.conf to allow:
local all all trust
I then restarted the postgres server so changes could be applied.
Then I opened command prompt and change directory to the bin folder of the postgres installation folder that has all the postgres .exe files.
From what I understand I am supposed to type the following:
psql -U postgres
And at this point it should let me in and should type:
ALTER USER postgres with password 'newpassword';
However, it keeps prompting me for password for user postgres:
And it just does not seem to be working. So from my understanding it seems that the the trust local rule in the pg_hba.conf is not really working correctly.
Update
My pg_hba.conf file only has the following uncommented tags in it:
host all all 127.0.0.1/32 trust
local all all trust
host all all ::1/128 md5
You seem to be asking to change the user on the operating system password. The Postgres user is a user on the the operating system.
Plus you are locked out due to the security hierarchy in Host Based Authentication (HBA)
host all all 127.0.0.1/32 trust
local all all trust
-> host all all ::1/128 md5 <-
NB Loopback Address - ::1/128
::1/128 is the loopback address of the local host which is the equivalent of the 127.0.0.1 in IPv4.
If the postgres user password (as in operating system user) is not set, the postgresq user password is stored
%APPDATA%\postgresql\pgpass.conf
Ref Location of postgresql default user password if not set
On Unix systems, the permissions on .pgpass must disallow any access to world or group; achieve this by the command chmod 0600 ~/.pgpass. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made.
You could update you Host Based Authentication (HBA) file and if you wanted to; change the password for the postgres user on the operating system or windows Then everything should be fine from psql
Hope this helps

psql.exe - password authentication failed in windows

I'm a noob in PostgreSQL. I installed ver 9.2 on windows7. During installation it asked for password and i entered it.
Now whenever i run d:\tools\PostgreSQL9.2\bin\psql.exe it asks for password. When i enter the password it doesn't accept and
it shows "password authentication failed for user "user1". I have re-installed twice already. Also i tried entering my system
password.
I'm trying to get the below command to work
psql.exe -f db/codedb.sql development
What should i do to get this working ?
Try setting the user name when connecting.
psql.exe -U username -d dbname -f somefile.sql
You've probably set up the default "postgres" user during installation. Not sure if you've created any others.
To add other users and databases just connect to as postgres to the postgres database and do something like:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;
If your machine is secure you might also like to set up a password file
change "trust" instead of "md5" in the pg_hba.conf to connect to the database and change your password.
--------------------configuration in pg_hba.conf---------------
local all all trust
local all postgres trust
host all all ::1/128 trust
Here is the simple solution for installation Postgresql without getting errors(cluster errors and authentication errors),i have followed below steps and i got installed postgresql sucessfully
create new user in windows from controlpanel-->user accounts
After logged into new user(whic u hve created) copy postrgresql(.exe) application into any directory(other than 'C') and click on the application to install(dont forget to change the installation directory to which u have copied the application file above).
after completion of installaion change below configurations in postgresql.conf and pg_hba.cof
add like below in your postgresql.conf
listen_addresses = '*'
add like below in your pg_hba.cof
# 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.
# host sameuser postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 md5