gpt4 book ai didi

Linux (Fedora) 无法在终端中运行 psql 命令 - 角色不存在

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:27 25 4
gpt4 key购买 nike

我已经在 stackoverflow 上看到了所有关于类似主题的问题,但我想知道为什么会发生这种情况,问题出在哪里,以及如何正确设置它。我正在学习编码,所以对于任何误解,我深表歉意。请耐心等待我。

我的情况是——

我无法从终端运行 psql 命令。

回应是——

psql: FATAL:  role "some_name" does not exist

在我写下并按回车键后 -

sudo -u postgres -i

一切正常,我可以运行 psql 命令。每次打开终端时,我都需要编写 sudo -u postgres -i 命令,一遍又一遍。

非常感谢任何回复。

如果您有更多问题,我可以为您提供更多信息。

在这里查看一些额外的信息:

[postgres@localhost ~]$ psql
psql (9.6.6)
Type "help" for help.

postgres=# \du
List of roles
Role name | Attributes | Member
of
-----------+------------------------------------------------------------+-------
----
matus | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

另一个:

[postgres@localhost ~]$ whoami
postgres

所以,我有两个打开的终端,一个是 postgres,另一个是 user_name,我可以在其中做其他事情,以某种方式使用 db。

最佳答案

根据您的描述,我想您在 hba 文件中有对等身份验证。要检查它,请使用 psql(您的 sudo -u postgres 方法)连接到 db 并:

t=# show hba_file ;
hba_file
---------------------
/pg/d10/pg_hba.conf
(1 row)
t=# \! grep local /pg/d10/pg_hba.conf | grep -v "#"
local all all peer

如果您看到同行高于信任,或者只是同行,情况并非如此。来自手册:

https://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-PEER

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping)

格式化我的。

所以为了避免

psql: FATAL: role "some_name" does not exist

只需创建这样的数据库用户:

create user some_name;

或者在hba.conf中将peer改为trust

关于Linux (Fedora) 无法在终端中运行 psql 命令 - 角色不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48177191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com