gpt4 book ai didi

linux - 库存 pg_hba.conf 文件中需要什么权限才能允许数据库角色进入?

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

我发现设置 pg_hba.conf 文件非常困难。这是浪费我时间的常见情况。我需要做什么?

首先,在 Amazon、Digital Ocean 或我自己的硬件上安装新安装的 Linux 发行版的虚拟机。我通常使用 Fedora 或 CentOS,然后通过以下方法获取 Postgres:

rpm -Uvh http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96 postgresql96-server postgresql96-contrib postgresql96-devel -y
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl enable postgresql-9.6
systemctl start postgresql-9.6
echo export PATH=/usr/pgsql-9.6/bin:"$PATH" >> /etc/profile.d/postgresql96.sh
yum update -y

只是为了排除一些问题,在防火墙上打个洞(这是开发 - 没关系)

firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload

创建数据库用户

su postgres
createuser --interactive -W bob
<answer yes to make bob a superuser>
psql
ALTER USER bob PASSWORD 'whatever';

编辑 /var/lib/pgsql/9.6/data/postgresql.conf 并将 #listen_addresses = 'localhost' 更改为 listen_addresses = '*'

重启

systemctl restart postgresql-9.6

现在,这就是事情总是横向发展的地方。

su postgres
psql -U bob -W
<enter password>
psql: FATAL: Ident authentication failed for user "bob"

我知道我需要在 pg_hba.conf 中做一些事情——但是应该在里面写什么?默认情况下它是这样说的:

# 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
# 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

我试过这个:

host all bob all md5

但这行不通。

我试过了

host all bob all ident

但这行不通。

我已经尝试从远程机器通过 TCP/IP 连接 pgadmin3,但这也不起作用,因为它在本地不起作用。

最后,我希望能够在本地以 bob 身份登录并通过 pgadmin3 远程登录。

更新:是否有网页清晰地解释了如何为一些典型用例设置 pg_hba.conf 文件?

最佳答案

ident 没用,不知道为什么包里还要用。请向 pgsql-bugs 报告有关 RPM 包的错误,以提示它们在本地主机 tcp/ip 连接上默认为 ident

host all bob all md5 应该没问题,虽然我通常会写

host all bob 0.0.0.0/0 md5
host all bob ::/128

那么...您确定重新加载了 PostgreSQL 的配置吗?

pg_ctl reload,重启数据库,或者SELECT pg_reload_conf()

或者,是否有任何较早的、未注释掉的条目匹配并导致屏蔽您的条目?

关于linux - 库存 pg_hba.conf 文件中需要什么权限才能允许数据库角色进入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45829644/

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