Fatal password authentication failed for user postgres ошибка

Authentication failures and related problems generally manifest themselves through error messages like the following:

FATAL:  no pg_hba.conf entry for host "123.123.123.123", user "andym", database "testdb"

This is what you are most likely to get if you succeed in contacting the server, but it does not want to talk to you. As the message suggests, the server refused the connection request because it found no matching entry in its pg_hba.conf configuration file.

FATAL:  password authentication failed for user "andym"

Messages like this indicate that you contacted the server, and it is willing to talk to you, but not until you pass the authorization method specified in the pg_hba.conf file. Check the password you are providing, or check your Kerberos or ident software if the complaint mentions one of those authentication types.

FATAL:  user "andym" does not exist

The indicated database user name was not found.

FATAL:  database "testdb" does not exist

The database you are trying to connect to does not exist. Note that if you do not specify a database name, it defaults to the database user name.

Tip

The server log might contain more information about an authentication failure than is reported to the client. If you are confused about the reason for a failure, check the server log.

Answer given is almost correct just missing some pointers which i’ll be taking care of in my solution

First make sure your user have a sudo access if not you can use the below command to add your user as sudo user :-

sudo adduser <username> sudo

The change will take effect the next time the user logs in.

i) Now go to sudo vim /etc/postgresql/<your_postgres_version>/main/pg_hba.conf file and look for line that says :

local   all             postgres                                md5 #peer

and comment that. Just below that line there must be a commented line that says:

local   all             postgres                                peer

or for older versions it’ll be :-

local   all         postgres                          ident

Uncomment that line.

ii) Now restart the postgres by using any of these commands :-

sudo /etc/init.d/postgresql restart

OR

sudo service postgresql restart

iii) Now you can simply log into postgres using the following command :

sudo -u postgres psql

iv) once you’re in you can create any operation you want to in my case i wanted to create a new database you can do the same using below command :

CREATE DATABASE airflow_replica;

PostgreSQL is an open-source database management system that allows the user to create relational databases using different CLI or GUI applications. The user will need to set the credentials for the servers which will be required while accessing the PostgreSQL server at any moment. Additionally, it enables the user to alter the passwords and credentials if the user has lost them.

This guide will explain how to solve the password authentication error for the user in PostgreSQL.

How to Solve the FATAL: Password Authentication Failed for User Postgres Error?

This error occurs in the PostgreSQL client application when the user provides the wrong password while connecting to the server:

img

To rectify the stated error, first, open the Notepad from the computer by clicking on the “Run as administrator” button:

img

Expand the “File” menu from the notepad and click on the “Open” button or press Ctrl+O from the keyboard:

img

Head into the “data” folder from the “PostgreSQL” directory to select the “pg_hba.conf” file and click on the “Open” button:

img

Scroll down to the bottom of the file to copy the last section of the file and store it on the local system:

img

After that, change the “scram-sha-256” with the “trust” keyword in the “METHOD” column, and click on the “Save” button from the “File” menu:

img

Open the “Run” dialog box from the local system:

img

Type the “services.msc” and click on the “OK” button:

img

Locate the “PostgreSQL” file from the list of all the services to click on it and then click on the “restart” button:

img

Restart the PostgreSQL client and it will allow the user to access the Postgres database to open the “Query Tool”:

img

Run the following query to change the password of the “postgres” user and then access the server using the newly provided password:

ALTER USER postgres WITH PASSWORD 'postgres';

img

Head back to the “pg_hba.conf” file from the “PostgreSQL” directory to select and change the “trust” with the “scram-sha-256” keyword:

img

Open the “Run” application one more time from the system:

img

Head into the “services.msc” page by clicking on the “OK” button:

img

Select the PostgreSQL file and click on the “Restart” button:

img

Open the PostgreSQL client to use the password and click on the “OK” button:

img

That’s all about solving the password authentication error while connecting to the server.

Conclusion

To solve the Fatal: password authentication failed for the user “postgres” error while connecting to the server, simply open the “pg_hba.conf” file. Change the values in the method column from the last section and then restart the PostgreSQL application from the “services.msc” application. Open the PostgreSQL client and change the password to log in to the server. This guide has explained the process of solving the password authentication failed error while connecting to the PostgreSQL server.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Assignees

@sameersbn

Comments

@StephanMeijer

$ sudo docker run --name postgresql -itd --restart always   --env 'PG_PASSWORD=postgres'   --env 'PG_TRUST_LOCALNET=true'   --publish 5432:5432   --volume /srv/docker/postgresql:/var/lib/postgresql   sameersbn/postgresql:9.6-2
59edeb353dec8c503a7f8d86396decfcdb31b98a3b463c3e9c990083fb4dc59e
$ psql -Upostgres -hlocalhost
Password for user postgres: 
psql: FATAL:  password authentication failed for user "postgres"
mauricedoepke, afourmy, Barbery, MrSwitch, mileslucas, iNLyze, zalper, dveselov, GopherJ, wsz87, and 39 more reacted with thumbs up emoji
Moathal and PGabriel20 reacted with heart emoji

@zalper

v10, still reproduced. Solution is:

You need to define a password for user postgres

  1. Get container
    docker ps

  2. Enter inside of the container
    docker exec -it <hash> bash

  3. Start query console
    psql

  4. Define password
    ALTER ROLE postgres WITH PASSWORD 'your_password';

Then you may grant other users as superuser and etc. (Make your volume persist)

Container Mgmnt:

Up:
docker-compose up —remove-orphans —force-recreate —build PostgreSQL

Down:
docker-compose down -v

AhmedBHameed, mcyleung, eduardorangell, kemicofa, birhanuh, Joostluijben, AnjaneyuluBatta505, ybuasen, AliA74, adrianchavez123, and 50 more reacted with thumbs up emoji
SergeyMMedvedev, dingobar, williandandrade, Robertmw, songtianyi, deadman2000, Myzel394, AIAL98, dimas-cyriaco, njfamirm, and 2 more reacted with thumbs down emoji
arogyakoirala, NightQnEarth, sterswift, daniel-covelli, Tanja-4732, jayanthdeejay, Alex-100, dan-developer, F-Yousri, vojahan, and Mrudul-Bhatt reacted with hooray emoji
Moathal, Mitjaaa, Alex-100, dan-developer, AhmedAlshoki, thebere, apexDev37, F-Yousri, vojahan, Mrudul-Bhatt, and obedNuertey1 reacted with heart emoji
obedNuertey1 reacted with rocket emoji
CodigoTotal01, quantum-samuel, u1viii, andriann-rak, Jarmos-san, PGabriel20, Mrudul-Bhatt, and obedNuertey1 reacted with eyes emoji

@AhmedBHameed

@zalper how should i save your steps in the container!!
I did your steps and commit the container but still now saved when running my image again !!
BTW i’m NB to docker.

@eddex

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

  • Option 1: Stop the PostgreSQL service on Windows
  • Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (sudo apt install postgresql-client-common postgresql-client libpq-dev)
  • Option 3: Change the port of the docker container
yondchang, bluwy, VShkaberda, TJBelcher, p3t3rix, mafrax, o-andres-u, nikluwfy, andersonmoura, Mallikanand, and 188 more reacted with thumbs up emoji
mjohnston-vtx, sqrnut-1, omneimneh, UUPRETI, IlyaBritkov, Dreammaker001, zcybupt, wolfwarrier14, grad44, WeiWeiCheng123, and 29 more reacted with hooray emoji
oLadeira, theding0x, DALLESANAA, ml-vines, CMofjeld, lalit-g-deepr, faragos, downtest, milijanadj, Hellin1, and 37 more reacted with heart emoji
nikluwfy, andersonmoura, khalilahmad0, danfmaia, exaucae, rbarthel, mjohnston-vtx, llltus, sqrnut-1, omneimneh, and 34 more reacted with rocket emoji

@august-of-wind

@eddex Just wanted to chime in to say your Option 1 above fixed this for me after I had been scratching my head for a couple of hours. That solution does not appear anywhere else online that I have been able to find and was extremely helpful. Thanks!

eddex, yondchang, exaucae, jtonikeetup, mjohnston-vtx, Lyakhova, omneimneh, lucasfpds, Quiarom, liekeceton, and 8 more reacted with hooray emoji

@TJBelcher

@eddex Thanks! I also benefited from you recalling your problem and solution. I’d not seen it mentioned anywhere else in 2 days of troubleshooting. I had noticed double use of the port in some netstat results, but reasoned it away as being 2 references to the same process since I didn’t know postgres 12 was running on my PC. Bad assumption on my part :)

@o-andres-u

@eddex Thanks a lot. I was having the same issue with my local Postgres installation and the container I was running by using docker. I just stopped the service on Windows and started working.

@nikluwfy

@eddex also saved the day for me here.

@Mallikanand

@eddex — after a couple of hours of struggle, this answer helped me.
Didnt realise my Postgres locally starts automatically upon login.
As I didnt need the local version anymore, uninstalled it.

@sameersbn

/remind me about this on saturday

@reminders

@reminders

@khalilahmad0

@STotev

I still got the issue and really don’t know what changed.
I was doing some work on my home machine and everything was set up properly and was working. Then I moved working on my working machine, set it up there and it worked as well (and it still works there).

After moving to my working machine I removed the containers and images for postgres:12 from my home machine. Now I want to set the things up again but for some reason it refuses to log me. Haven’t changed any docker-compose settings.
I am afraid that if I now remove everything from my working machine and try to set it up again, it’ll stop working there too.

This is my docker-compose.yml file.

version: '3.1'

services:

    postgres:
        image: postgres:12
        container_name: "postgres-v12"
        ports:
            - 5432:5432
        environment:
            POSTGRES_PASSWORD: admin
        volumes:
            - db_vol:/var/lib/postgresql/data

    pgadmin:
        image: dpage/pgadmin4
        container_name: pgadmin4
        ports:
            - 3333:80
        environment:
            PGADMIN_DEFAULT_EMAIL: admin
            PGADMIN_DEFAULT_PASSWORD: admin


volumes:
    db_vol:
        external:
            name: "postgres-v12"

I don’t have postgres installed directly on my machine, tried to change ports, passwords, adding networks, re-pulling images, restarting docker etc. and it just won’t work.

Any ideas anyone?

@STotev

Today, I have decided to try and re-create the volume. So I deleted this postgres-v12 and created a new one and just in case I named it postgres12. I updated docker-compose.yml and voila everything started working again. I have never done any manual user updates, so somehow something messed up the postgres user in that volume.

@exaucae

Thanks @eddex ! Solution 1 fixed my issue.

@Maxeeezy

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

  • Option 1: Stop the PostgreSQL service on Windows
  • Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (sudo apt install postgresql-client-common postgresql-client libpq-dev)
  • Option 3: Change the port of the docker container

Do you maybe also know a solution for Mac OSX? I already spent hours on this bad connection error for this docker issue…

@Maxeeezy

In my case (dockerizing a rails app) I had to delete tmp/db folder and rerun docker-compose up for me to solve the issue.

@kamalhm

almost went crazy because I have tried even reinstalling docker to solve this issue, turns out it was because I forgot I installed a local postgresql. 🤪 thanks @eddex

@l-narasimhan

Today, I have decided to try and re-create the volume. So I deleted this postgres-v12 and created a new one and just in case I named it postgres12. I updated docker-compose.yml and voila everything started working again. I have never done any manual user updates, so somehow something messed up the postgres user in that volume.

It worked for me as well

@nox-mthimkulu

I had the same issue with just running
docker run --name pg -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres and I eventually realised that the command was using the postgres docker image that I had locally, tagged as latest (rather than pulling the latest one from remote).
Run d
docker image ls

and see what images you currently have. Removing the postgres:latest image I had locally and re-running the command ended up with the latest image being pulled and the login working!

@JustifydWarrior

this worked for me… i just forward and expose 5435 on my machine. leave pg on 5432 inside the container. Then it’s easy to config 5435 or any other port for dev use.

services:
  database:
    image: "postgres" # use latest official postgres version
    env_file:
      - database.env # configure postgres
    volumes:
      - database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
    ports:
      - 5435:5432
    expose:
      - "5435"

volumes:
  database-data: # named volumes can be managed easier using docker-compose

my database.env for reference

  PGUSER=postgres
  PGPASSWORD=postgres
  PGDATABASE=postgres
  POSTGRES_USER=postgres
  POSTGRES_PASSWORD=postgres
  POSTGRES_DB=postgres

yes it’s been redacted. i am not actually forcing the default values. just wanted to clarify the file structure and proper envs as noted here: https://www.postgresql.org/docs/9.3/libpq-envars.html

in addition to the others the docker container uses.

there seems to be no reason for 2 different sets of envs, but i haven’t thought through every use case.

so perhaps that’s a possible fix here is using the core PG envs and then update container docs to match.

@Limatucano

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

  • Option 1: Stop the PostgreSQL service on Windows
  • Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (sudo apt install postgresql-client-common postgresql-client libpq-dev)
  • Option 3: Change the port of the docker container

You are so beautiful, THANKSS

@Chicitadel

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

* Option 1: Stop the PostgreSQL service on Windows

* Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (`sudo apt install postgresql-client-common postgresql-client libpq-dev`)

* Option 3: Change the port of the docker container

You saved me tons of painful 72hours of battle with innocent Intellij IDE and plugins

@bibhuticoder

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

  • Option 1: Stop the PostgreSQL service on Windows
  • Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (sudo apt install postgresql-client-common postgresql-client libpq-dev)
  • Option 3: Change the port of the docker container

Faced the same issue. Solved it by changing port mapping on docker-compose

services:
  db:
    image: postgres
    container_name: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: ***
      POSTGRES_USER: ***
      POSTGRES_DB: ***
    ports:
      - 5435:5432    ==> changed 5432 to 5435

@gustavorps

@jeremybradbury

@gustavorps I think the solution is an easy one to work around. Using @JustifydWarrior’s fix above:

    ports:
      - 5435:5432
    expose:
      - "5435"

5433 and 5434 are also reserved for more common uses, however 5435 is not a very common protocol by definition & is most often used as a second postgres port.

@bibhuticoder came up with the same solution.

I think someone should submit a PR to fix this, even if it is a second docker compose file, simply called by using the filename flag.

Disabling the default service, is the simplest solution, but that shouldn’t be the preferred workaround, many of us need both running.

@fahricankacan

I had the same problem . My solution for windows :

  1. Stop docker container
  2. win + r and type services.msc
  3. Find postgressql and stop
  4. Start your container again

I solved my problem with this way .

arkhio99, deonvisser44, bogdankis, anildalar, JOSEPHOMOTOSHO, vitoc15, tangjienan, PieroCahuanaPalomino, Natasha-eng, ysfrdvn, and 4 more reacted with thumbs up emoji
bogdankis and ysfrdvn reacted with laugh emoji
thosaphol, akrom123, ysfrdvn, and serjteplov reacted with heart emoji

@escote

Envs are used by postgres initdb to create your postgresql instance. If you changed yours envs after first execution, you need to delete the postgres container to force a recreation using new envs. If you have defined a volume, you will also need to remove it.

@thalles-victor

My english is not very well, but i try help you.

In your project run

if exist a folder called database-data (name of the your volume of postgres of the docker-compose.yml), remove this folder and run again

  docker-compose up -d --force-recreate

The my work this way.

Or
if it didn’t work, try
Remove all volumes outside project with

  docker volume rm $(docker volume ls -q)

and run again
«`console`
docker-compose up -d —force-recreate
«

@coding-x1

Below is my postgres:14 in the docker-compose.yml

I am writing Go Program in the microservice manner.
One day before POSTGRES_PASSWORD: password
was the password. Next day I changed POSTGRES_PASSWORD: secret
Now the said error came.

The folder /db-data/postgres/ which I mentioned below has content populated by docker.
Deleted that content and again run docker. Now ok.

postgres:
image: ‘postgres:14.0’
ports:
— «5432:5432»
restart: always
deploy:
mode: replicated
replicas: 1
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
POSTGRES_DB: users
volumes:
— ./db-data/postgres/:/var/lib/postgresql/data/

@anildalar

@eddex Thanks a lot. I was having the same issue with my local Postgres installation and the container I was running by using docker. I just stopped the service on Windows and started working.

THanks it works for me

@tommy4421

A uppercase character in the username will also trigger this error message…

@GSpletty

I had a similar issue, probably not related to the one of @zalper but with the same error message so I’ll leave the solution here for anyone having the same problems.

I’m using Windows and had ProstgreSQL 12 installed.

At the same time I tried to run a postgres:10 docker container.

When I tried to connect to the database running in the docker container using psql, I always got an error saying psql: FATAL: password authentication failed for user "postgres".

The issue was that the postgres docker container was using the default port 5432 on localhost and the PostgreSQL server on Windows was using the same port on localhost. However, there were no errors when starting either of them.

Solutions:

  • Option 1: Stop the PostgreSQL service on Windows
  • Option 2 (using WSL): Completely uninstall Protgres 12 from Windows and install postgresql-client on WSL (sudo apt install postgresql-client-common postgresql-client libpq-dev)
  • Option 3: Change the port of the docker container

Stopping the postgres service and uninstalling from Windows was my exact issue

@merlincdj

Below is my postgres:14 in the docker-compose.yml

I am writing Go Program in the microservice manner. One day before POSTGRES_PASSWORD: password was the password. Next day I changed POSTGRES_PASSWORD: secret Now the said error came.

The folder /db-data/postgres/ which I mentioned below has content populated by docker. Deleted that content and again run docker. Now ok.

postgres: image: ‘postgres:14.0’ ports: — «5432:5432» restart: always deploy: mode: replicated replicas: 1 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: secret POSTGRES_DB: users volumes: — ./db-data/postgres/:/var/lib/postgresql/data/

This work for me, thank you!

@Andrewsoares15

@eddex after two days of reading all of these forums, I finally found your solution, you saved my life hahaha Thanks my brotha!!

Skip to content

In this article, we will see the solution for error “FATAL: password authentication failed for user “postgres””.

FATAL:  password authentication failed for user "postgres"

1. Reason is the user postgres has no DB password set on Ubuntu by default. That means, that you can login to that account only by using the postgres OS user account.

sudo -u postgres psql

2. Now set the password for user ‘postgres’;

alter user postgres with password 'admin@123';

3. If any of those commands fail with an error psql: FATAL: password authentication failed for user “postgres” then check the file /etc/postgresql/8.4/main/pg_hba.conf: There must be a line like this as the first non-comment line:

local all postgres ident

Reload postgresql server after modifying pg_hba.conf file.

Понравилась статья? Поделить с друзьями:
  • Fallout 76 произошла неизвестная ошибка
  • Fallout 76 ошибка при создании учетной записи
  • Fallout 76 ошибка идентификации квест
  • Fallout 76 ошибка noregionping
  • Far cry 6 ошибка при запуске внимание