且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Postgresql:用户"postgres"的密码身份验证失败

更新时间:2021-11-13 08:31:18

如果我没有记错的话,默认情况下,用户postgres在Ubuntu上没有设置 DB 密码.这意味着,您只能使用postgres OS用户帐户登录该帐户.

If I remember correctly the user postgres has no DB password set on Ubuntu by default. That means, that you can login to that account only by using the postgres OS user account.

假设您可以在框中执行root访问权限,

Assuming, that you have root access on the box you can do:

sudo -u postgres psql

如果失败并显示database "postgres" does not exists错误,则您很可能不在Ubuntu或Debian服务器上:-)在这种情况下,只需在命令中添加template1:

If that fails with a database "postgres" does not exists error, then you are most likely not on a Ubuntu or Debian server :-) In this case simply add template1 to the command:

sudo -u postgres psql template1

如果这些命令中的任何一个因错误psql: FATAL: password authentication failed for user "postgres"而失败,则检查文件/etc/postgresql/8.4/main/pg_hba.conf:必须有这样的行作为第一行非注释行:

If any of those commands fail with an error psql: FATAL: password authentication failed for user "postgres" then check the file /etc/postgresql/8.4/main/pg_hba.conf: There must be a line like this as the first non-comment line:

local   all         postgres                          ident

对于PostgreSQL的较新版本,ident实际上可能是peer.没关系.

For newer versions of PostgreSQL ident actually might be peer. That's OK also.

psql外壳程序内,您可以为 DB用户 postgres设置密码:

Inside the psql shell you can give the DB user postgres a password:

ALTER USER postgres PASSWORD 'newPassword';

您可以通过键入 Ctrl D 或使用命令\q离开psql外壳.

You can leave the psql shell by typing CtrlD or with the command \q.

现在,您应该能够为pgAdmin提供数据库超级用户的有效密码,这也将很高兴. :-)

Now you should be able to give pgAdmin a valid password for the DB superuser and it will be happy too. :-)