且构网

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

PostgreSQL错误:致命:角色“用户名"不存在

更新时间:2022-10-31 13:34:20

使用操作系统用户 postgres创建数据库-只要您尚未设置具有必需特权的数据库角色,该角色对应于您的同名操作系统用户(在您的情况下为h9uest):

Use the operating system user postgres to create your database - as long as you haven't set up a database role with the necessary privileges that corresponds to your operating system user of the same name (h9uest in your case):

sudo -u postgres -i

此处此处.

然后重试.以系统用户postgres的身份完成操作后,键入exit.

Then try again. Type exit when done with operating as system user postgres.

将单个命令createuser作为postgressudo一起执行,例如 Drees 在另一个答案中.

Or execute the single command createuser as postgres with sudo, like demonstrated by drees in another answer.

重点是使用与具有相同名称的数据库角色匹配的操作系统用户来通过 ident身份验证 . postgres是已初始化数据库集群的默认操作系统用户. 手册:

The point is to use the operating system user matching the database role of the same name to be granted access via ident authentication. postgres is the default operating system user to have initialized the database cluster. The manual:

为了引导数据库系统,请重新初始化 系统始终包含一个预定义角色.这个角色永远是 超级用户",默认情况下(除非在运行initdb时进行了更改) 将具有与初始化的操作系统用户相同的名称 数据库集群.通常,此角色将被命名为postgres. 为了创建更多角色,您首先必须以此连接 最初的角色.

In order to bootstrap the database system, a freshly initialized system always contains one predefined role. This role is always a "superuser", and by default (unless altered when running initdb) it will have the same name as the operating system user that initialized the database cluster. Customarily, this role will be named postgres. In order to create more roles you first have to connect as this initial role.

我听说过使用非标准用户名或操作系统用户不存在的奇怪设置.您需要在那里调整策略.

I have heard of odd setups with non-standard user names or where the operating system user does not exist. You'd need to adapt your strategy there.

了解有关数据库角色 查看全文