Psql ошибка пользователь не прошел проверку подлинности

Поставил postgresQL на свой пк (Windows). Учусь всякие штуки делать на nestjs. Нужна именно эта база. Проблема: захожу в терминале предварительно выбрав папку где лежит psql

.psql -v

на что мне терминал отвечает:

Пароль пользователя Admin:

Ввожу пароль от своего аккаунта на ПК. И происходит ошибка:

psql: ошибка: подключиться к серверу «localhost» (127.0.0.1), порту
5432 не удалось: ВАЖНО: пользователь «Admin» не прошёл проверку
подлинности (по паролю)

Думал может не на той раскладке или Nun Lock зажат. все проверил.
В итоге решил зайти через pgAdmin4 — та же база, только в виде программы с интерфейсом под windows.
Просит пароль. ввожу тот же пароль, все нормально работает.
Нужно именно из строки как то заходить. Есть мысли что не так?

задан 18 янв 2022 в 10:53

Андрей's user avatar

pgAdmin -> там вводишь свой пароль и появится стандартное окно Welcome -> в Quick Links будет Add New Server -> там заполняешь и сохраняешь (не обязательно всё, можно заполнить только General, Connetcion). Теперь в консоли сможешь подключаться к нему. (На всякий случай поясню. При подключение используешь имя и пароль, которые задавал при создании этого сервера)

ответ дан 10 мая 2022 в 10:49

Akayo's user avatar

тоже была такая проблема, с паролем и не находил путь.

решение:

  1. прописал путь в переменных средах.
  2. Работает только через командную строку, через PowerShell не работает (у меня)

aleksandr barakin's user avatar

ответ дан 4 ноя 2022 в 21:15

Andryu's user avatar

2

Выполни в консоли:
psql -U postgres
затем введи пароль, который вводил, когда заходил через pgAdmin4. Должно помочь.
Через консоль ты логинешься через системную учетку, которой нет в postgres.
Команда «psql -U USERNAME» позволяет авторизоваться под учеткой USERNAME.
Надеюсь поможет.

ответ дан 26 дек 2022 в 19:27

Romul Fobos's user avatar

Поставил Постгрес-сервер 11, подключился как пользователь postgres, создал юзера, создал БД, вышел.
Подключился опять как postgres и решил зайти под новым пользователем, ввел команду —
psql -h localhost db_inter_pas lightSql
Вывод —

psql: ВАЖНО:  пользователь "lightSql" не прошёл проверку подлинности (Ident)

Пробовал так — psql -U lightSql -h localhost -d db_inter_pas
Вывод —

psql: ВАЖНО:  пользователь "lightSql" не прошёл проверку подлинности (Ident)

При этом я в конфиге разкоментировал строку — listen_addresses = ‘localhost’
Почему? Как исправить?

Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

# TYPE DATABASE USER ADDRESS METHOD
local  all      all          peer

to

# TYPE DATABASE USER ADDRESS METHOD
local  all      all          md5
  • peer means it will trust the identity (authenticity) of UNIX user. So not asking for a password.

  • md5 means it will always ask for a password, and validate it after hashing with MD5.

  • trust means it will never ask for a password, and always trust any connection.

You can, of course, also create more specific rules for a specific database or user, with some users having peer and others requiring passwords.

After changing pg_hba.conf you’ll need to restart PostgreSQL if it’s running. E.g. sudo service postgresql restart

Steps to change/create default postgres user’s password:
  1. trust connection by adding in pg_hba.conf file
  • local all postgres trust
  1. Restart postgresql service
  • sudo service postgresql restart
  1. psql -U postgres

  2. At the postgres=# prompt, change the user name postgres password:

  • ALTER USER postgres with password ‘new-password’;
  1. Revert the changes in pg_hba.conf file from trust to md5 and restart postgresql.
pg_hba.conf file location

The file pg_hba.conf will most likely be at /etc/postgresql/9.x/main/pg_hba.conf
To check location of pg_hba.conf connect to postgres db using psql then type SHOW hba_file; command.

After change pg_hba.conf file, you can execute SELECT pg_reload_conf(); or pg_ctl reload with superuser instead of restart postgresql service.

* Source

Say you’re seeing this message:

FATAL:  Ident authentication failed for user "..."

What are the causes of this error message?

Cristian Ciupitu's user avatar

asked Jul 11, 2012 at 0:44

Steve Bennett's user avatar

Steve BennettSteve Bennett

5,71012 gold badges47 silver badges57 bronze badges

It means that Postgres is trying to authenticate a user using the Ident protocol, and can’t. Ident auth automatically matches Unix usernames with Postgres usernames. It works like this:

  • You have database role ‘foo’ on database ‘db’
  • Your pg_hba.conf file (in /etc/postgres-something/main) defines ‘Ident’ as the protocol to connect to database db for users connecting from certain hosts
  • The unix username making the connection is ‘foo’
  • An Ident server running on the machine the user is connecting from confirms that their username really is ‘foo’

Possible causes and solutions:

  1. There is no Ident server running on the machine you’re trying to connect from. Test this by trying to connect to it on port 113. If that fails, install an Ident server (eg, sudo apt-get install oidentd).

  2. There’s an Ident server, but there’s no database role matching the name you’re trying to connect with (‘foo’ in the above example). So create it by connecting somehow to the database with superuser rights and do CREATE ROLE foo. Alternatively add an entry to /etc/postgresql/.../main/pg_ident.conf (or /var/lib/pgsql/12/data or wherever).

  3. Maybe the shell username doesn’t match the database role. You may be able to test this by connecting to the Ident server while a connection is going on, and passing the right port numbers.

  4. Maybe you actually want to connect with a password, not Ident. Edit the pg_hba.conf file appropriately. For example, change:

    host all all 127.0.0.1/32 ident
    

to

    host all all 127.0.0.1/32 md5

Be sure to restart Postgres after updating the pg_hba.conf file. You do that by issuing the following command:

    sudo service postgresql-12 restart
   

answered Jul 11, 2012 at 0:44

Steve Bennett's user avatar

Steve BennettSteve Bennett

5,71012 gold badges47 silver badges57 bronze badges

7

Not sure about the causes, but this fixed it for me:

in pg_hba.conf

change to this:

host all all 127.0.0.1/32 md5

Exact error: Caused by: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "postgres"

answered Sep 10, 2012 at 15:21

jacktrades's user avatar

1

For Centos 7, Change pg_hba.conf to below:

# 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            ident
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
#host    all             all             ::1/128                 ident
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            ident
#host    replication     all             ::1/128                 ident

Demur Rumed's user avatar

answered Apr 9, 2020 at 7:00

KulJeet's user avatar

KulJeetKulJeet

511 silver badge1 bronze badge

0

On CentOS, add the following line to /var/lib/pgsql/9.3/data/pg_hba.conf:

host all all 127.0.0.1/32 trust

And comment out the other entries.

Of course, this setting is not secure, but if you’re just messing about on a development VM like me then it’s probably fine…

answered Jul 14, 2014 at 11:11

XåpplI'-I0llwlg'I  -'s user avatar

0

Try to use -h 127.0.0.1 instead of -h localhost

answered May 27, 2021 at 13:55

despotbg's user avatar

If you have not tried this already, review your pg_hba.conf file. It will be named something like /var/lib/pgsql/9.3/data/pg_hba.conf (Fedora 20); you may have to use ‘find / -name pg_hba.conf’ to locate it.

At the bottom of the file, change the ‘METHOD’ values to ‘trust’ for local testing (see postgres docs for full information). Reboot the machine to ensure everything is started clean and the new params are read.

Hopefully this will cure your woes. It solved my problems on Fedora 20 with PostgreSQL 9.3.

answered Jul 26, 2014 at 0:59

Alan Thompson's user avatar

1

Помогите разобраться народ !!!
Установлен PostgreSQL 9.6
Это моя настройка в pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD
LOCAL   ALL             postgres                                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

Задан пароль пользователю «postgres» в Ubuntu
sudo echo -e «PAROLnPAROLn» | passwd postgres;
Пароль пользователю «postgres» в базе был задан:
sudo -U postgres psql -c «ALTER USER postgres WITH ENCRYPTED PASSWORD ‘PAROL’;»
Перезапускаю service postgresql restart
В результате, в логах:

2017-03-09 14:55:43 MSK [11185-1] СООБЩЕНИЕ:  система БД была выключена: 2017-03-09 14:55:42 MSK
2017-03-09 14:55:43 MSK [11185-2] СООБЩЕНИЕ:  Защита от наложения мультитранзакций сейчас включена
2017-03-09 14:55:43 MSK [11184-1] СООБЩЕНИЕ:  система БД готова принимать подключения
2017-03-09 14:55:43 MSK [11189-1] СООБЩЕНИЕ:  процесс запуска автоочистки создан
2017-03-09 14:55:44 MSK [11191-1] [н/д]@[н/д] СООБЩЕНИЕ:  неполный стартовый пакет
2017-03-09 14:55:44 MSK [11194-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:44 MSK [11194-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:45 MSK [11197-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:45 MSK [11197-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:45 MSK [11200-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:45 MSK [11200-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:46 MSK [11203-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:46 MSK [11203-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:46 MSK [11206-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:46 MSK [11206-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:47 MSK [11209-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:47 MSK [11209-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:47 MSK [11212-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:47 MSK [11212-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:48 MSK [11215-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:48 MSK [11215-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:48 MSK [11218-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:48 MSK [11218-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:49 MSK [11221-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:49 MSK [11221-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:49 MSK [11224-1] postgres@postgres ВАЖНО:  пользователь "postgres" не прошёл проверку подлинности (по паролю)
2017-03-09 14:55:49 MSK [11224-2] postgres@postgres ПОДРОБНОСТИ:  Пароль не подходит для пользователя "postgres".
	Подключение соответствует строке 86 в pg_hba.conf: "local   all             postgres                                md5"
2017-03-09 14:55:49 MSK [11184-2] СООБЩЕНИЕ:  получен запрос на "вежливое" выключение
2017-03-09 14:55:49 MSK [11189-2] СООБЩЕНИЕ:  процесс запуска автоочистки завершается
2017-03-09 14:55:49 MSK [11186-1] СООБЩЕНИЕ:  выключение
2017-03-09 14:55:49 MSK [11184-3] СООБЩЕНИЕ:  система БД выключена

Понравилась статья? Поделить с друзьями:
  • Psql ошибка подключиться к серверу через сокет
  • Psql ошибка отношение не существует
  • Psql ошибка не удалось подключиться к серверу важно пользователь
  • Psql ошибка не удалось подключиться к серверу connection refused
  • Psql ошибка важно роль user не существует