Rac*_*ana 5 postgresql pgadmin
我已经在 Ubuntu 20.04 上安装了 Postgres 和 PGAdmin4,但无法创建服务器并连接到数据库
正如我在几个解决方案中看到的,我将 pg_hba.conf 文件上的方法更改为 md5
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Run Code Online (Sandbox Code Playgroud)
我还连接到 psql,创建新用户,更改密码并通过运行重新启动服务器sudo systemctl restart postgresql
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
小智 7
运行以下命令:
sudo -i -u postgres
Run Code Online (Sandbox Code Playgroud)
输入您的 sudo 用户密码
psql
ALTER USER postgres PASSWORD 'new_password';
\q
exit
Run Code Online (Sandbox Code Playgroud)
现在更改配置文件以使用此新密码:
sudo subl /etc/postgresql/13/main/pg_hba.conf
Run Code Online (Sandbox Code Playgroud)
(subl表示 subliime text,您可以使用任何其他文本编辑器)。
编辑文件的这一部分:将peer更改为md5
# Database administrative login by Unix domain socket
local all postgres peer
# "local" is for Unix domain socket connections only
local all all peer
Run Code Online (Sandbox Code Playgroud)
重新启动 postgres 服务
运行以下命令以使用新创建的密码登录 postgres:
psql -U postgres
Run Code Online (Sandbox Code Playgroud)