更新时间: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
作为postgres
与sudo
一起执行,例如 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 namedpostgres
. 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.