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

在配置PostgreSQL 9.1时遇到错误:角色“username”不存在。问题涉及数据库角色、操作系统用户和认证。建议使用与数据库角色同名的操作系统用户创建数据库,并通过特定命令授予访问权限。如果操作系统用户不存在,需要调整策略。创建具有超级用户权限的role并允许登录,可以解决登录问题。
摘要由CSDN通过智能技术生成

本文翻译自:PostgreSQL error: Fatal: role “username” does not exist

I'm setting up my PostgreSQL 9.1. 我正在设置我的PostgreSQL 9.1。 I can't do anything with PostgreSQL: can't createdb , can't createuser ; 我不能做任何事情的PostgreSQL:不能createdb ,不能createuser ; all operations return the error message 所有操作都返回错误消息

Fatal: role h9uest does not exist

h9uest is my account name, and I sudo apt-get install PostgreSQL 9.1 under this account. h9uest是我的帐户名,我在这个帐户下sudo apt-get install PostgreSQL 9.1。
Similar error persists for the root account. root帐户仍然存在类似的错误。


#1楼

参考:https://stackoom.com/question/o0mF/PostgreSQL错误-致命-角色-用户名-不存在


#2楼

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): 使用操作系统用户 postgres创建数据库 - 只要您没有设置具有与您的同名操作系统用户相对应的必要权限的数据库角色(在您的情况下为h9uest ):

sudo -u postgres -i

As recommended here or here . 这里这里推荐。

Then try again. 然后再试一次。 Type exit when done with operating as system user postgres . 完成操作系统用户postgres键入exit

Or execute the single command createuser as postgres with sudo , like demonstrated by drees in another answer. 或者使用sudo执行单个命令createuser as postgres ,如另一个答案中的drees所示

The point is to use the operating system user matching the database role of the same name to be granted access via ident authentication . 关键是使用与同名数据库角色匹配的操作系统用户通过ident验证授予访问权限。 postgres is the default operating system user to have initialized the database cluster. postgres是初始化数据库集群的默认操作系统用户。 The manual: 手册:

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. 此角色始终是“超级用户”,默认情况下(除非在运行initdb时更改),它将与初始化数据库集群的操作系统用户具有相同的名称。 Customarily, this role will be named postgres . 通常,此角色将命名为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. 你需要在那里调整你的策略。

Read about database roles and client authentication in the manual. 阅读手册中的数据库角色客户端身份验证


#3楼

After trying many other peoples solutions, and without success, this answer finally helped me. 在尝试了许多其他人的解决方案后,没有成功,这个答案终于帮助了我。

https://stackoverflow.com/a/16974197/2433309 https://stackoverflow.com/a/16974197/2433309

In short, running 总之,跑步

sudo -u postgres createuser owning_user

creates a role with name owning_user (in this case, h9uest). 创建一个名为owning_user的角色(在本例中为h9uest)。 After that you can run rake db:create from the terminal under whatever account name you set up without having to enter into the postgres environment. 之后,您可以在您设置的任何帐户名下从终端运行rake db:create ,而无需进入postgres环境。


#4楼

sudo su - postgres

psql template1

creating role on pgsql with privilege as "superuser" 在pgsql上创建角色,权限为“超级用户”

CREATE ROLE username superuser;
eg. CREATE ROLE demo superuser;

Then create user 然后创建用户

CREATE USER username; 
eg. CREATE USER demo;

Assign privilege to user 为用户分配权限

GRANT ROOT TO username;

And then enable login that user, so you can run eg: psql template1 , from normal $ terminal: 然后启用登录该用户,这样你就可以运行eg: psql template1 ,从普通的$ terminal:

ALTER ROLE username WITH LOGIN;

#5楼

这对我有用:

psql -h localhost -U postgres

#6楼

In local user prompt, not root user prompt, type 在本地用户提示符下,不是root用户提示符,键入

sudo -u postgres createuser <local username>

Then enter password for local user. 然后输入本地用户的密码。

Then enter the previous command that generated "role 'username' does not exist." 然后输入生成“角色'用户名'不存在的上一个命令。”

Above steps solved the problem for me. 上面的步骤解决了我的问题。 If not, please send terminal messages for above steps. 如果没有,请发送以上步骤的终端消息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值