我正在使用这个引用在amazon linux上安装postgres-12:https://techviewleo.com/install-postgresql-12-on-amazon-linux/
它的核心是:
sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
[pgdg12]
name=PostgreSQL 12 for RHEL/CentOS 7 - x86_64
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF
sudo yum makecache
sudo yum install postgresql12 postgresql12-server
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable --now postgresql-12
systemctl status postgresql-12此安装确实有效:postgresql已启动。但它只允许通过postgres用户进行本地连接。我一直试图让md5密码验证运行,但它不工作。
]$ psql -U pubkey
psql: error: could not connect to server: FATAL: Peer authentication failed for user "pubkey"下面是pg_hba.conf:注意它确实有
local all all md5# "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
host all all 0.0.0.0/32 md5
# IPv6 local connections:
local all all md5
host all all ::1/128 ident
# 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在添加了md5行之后,我重新启动了postgres:
sudo systemctl stop postgresql-12
sudo systemctl start postgresql-12但是密码身份验证仍然不起作用。我遗漏了什么?
发布于 2020-08-21 00:21:41
你做了教程的这一部分吗?
-bash-4.2$ psql -c "alter user postgres with password 'StrongPassword'"
ALTER ROLE如果是这样,要使用密码(Md5)身份验证,您需要执行以下操作:
psql -d postgres -U postgres -h localhost如果没有-h,您将通过套接字(在pg_hba.conf中为本地)并使用peer身份验证进行连接。
我还会注释掉/删除/或移动到IPv4本地连接的底部:
host all all 127.0.0.1/32 ident
在pg_hba.conf first match中获胜,因此如果您通过localhost(pg_hba.conf中的主机)和ipv4进行连接,它将查找ident身份验证。
所有的解释都在这里:
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html
https://stackoverflow.com/questions/63509111
复制相似问题