use*_*782 6 postgresql debian psql
我正在使用 psql 连接到 Debian 10 上的 PostgreSQL 数据库。我尝试以postgres用户身份连接到默认的postgres数据库。默认情况下,这是使用“对等”身份验证方法,不需要密码。
如果我使用“对等”身份验证登录并使用以下命令设置密码:
ALTER USER postgres WITH PASSWORD 'myPassword';
Run Code Online (Sandbox Code Playgroud)
查询成功执行,但是当我编辑 pg_hba.conf 以更改身份验证方法时:
local all postgres peer
Run Code Online (Sandbox Code Playgroud)
到:
local all postgres scram-sha-256
Run Code Online (Sandbox Code Playgroud)
并重新启动服务器,我收到以下错误:
~$ sudo -u postgres psql postgres
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
~$
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?
要更改 PostgreSQL 中的身份验证方法:
\n打开终端窗口
\n切换到 postgres bin 目录
\n例子: cd /usr/local/pgsql/bin
注意:根据您的安装环境,bin 目录的路径可能会有所不同。
\n键入su \xe2\x80\x93 postgres并按 Enter 键。这将更改登录的postgres用户。
从 bin 目录类型./psql
键入:\n ALTER USER your_username password \'new_password\';并按 Enter 键。 ALTER ROLE应该显示。
输入\\q并按 Enter 键
打开/path_to_data_directory/pg_hba.conf
例子: /etc/postgresql/11/main/pg_hba.conf
注意:您可能只需将单词更改trust为md5。该行或多行应该已经存在。
host all postgres peer \nhost all your_username your.ip your.subnet md5\nRun Code Online (Sandbox Code Playgroud)\n保存更改
\n重新启动 PostgreSQL 服务systemctl restart postgresql.service
| 归档时间: |
|
| 查看次数: |
8493 次 |
| 最近记录: |