linux - Postgres : psql: FATAL: role "postgres" does not exist

标签 linux postgresql

我已经使用 PostgreSQL 几天了,它运行良好。我一直在通过默认的 postgres 数据库用户和另一个具有权限的用户使用它。

今天中午(在一切正常之后)它停止工作,我再也无法回到数据库中。我会尝试:psql,它会出现 psql: FATAL: role "postgres"does not exist

类似地,如果我从我的其他用户那里尝试,psql -d postgres 它会出现 psql: FATAL: role "otheruser"does not exist。 (请注意,我有一个名为 postgres 的数据库,它一直运行到现在)。

更新

似乎其中一台访问服务器的计算机崩溃了,并且可能以某种方式删除了数据库的所有用户。我会尝试重新安装。

最佳答案

psql无法登录的情况下查看哪些用户存在,可以使用以下方法:

  • 停止 postgres
  • 以单用户模式重启它(指定数据目录)
  • 查询pg_user全局表
  • 正常重启postgres

例子:

$ sudo -i -u postgres
...
postgres@u64:/usr/local/pg95a1$ bin/postgres --single -D $PWD/data

PostgreSQL stand-alone backend 9.5alpha1
backend> select usename from pg_user;
     1: usename (typeid = 19, len = 64, typmod = -1, byval = f)
    ----
     1: usename = "postgres"    (typeid = 19, len = 64, typmod = -1, byval = f)
    ----
     1: usename = "daniel"  (typeid = 19, len = 64, typmod = -1, byval = f)
    ----
     1: usename = "joe" (typeid = 19, len = 64, typmod = -1, byval = f)
    ----
     1: usename = "bob" (typeid = 19, len = 64, typmod = -1, byval = f)
    ----

ctrlD 终止单用户 session 。

关于linux - Postgres : psql: FATAL: role "postgres" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31464806/

相关文章:

即使不需要 xserver,Java 应用程序也会抛出 `Gtk-WARNING **: cannot open display:`

linux - 如何将 Linux 终端配置为在输出 "\n"时仅换行(而不是回车)?

linux - 如何记录内核 panic 消息?

postgresql异常运算符不存在: uuid = bytea

c++ - 如何使用 C++ 浏览目录以创建文件资源管理器

php - 通过php打开DS更新

postgresql - PL/pgSQL 风格指南

PostgreSQL/PGAdmin4 错误 : there is no unique constraint matching given keys for referenced table

sql - 同一表上的传递 SQL 查询

postgresql - 如何在 postgres 中创建 super 用户帐户