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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28276706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:53:45  来源:igfitidea点击:

PostgreSQL error Fatal: role “username” does not exist

postgresqlwindows-7windows-7-x64roles

提问by Abhishek

I'm setting up my PostgreSQL 9.1 in windows.

我正在 Windows 中设置我的 PostgreSQL 9.1。

I can't do anything with PostgreSQL: can't createdb, can't createuser; all operations return the error message

我不能用 PostgreSQL 做任何事情:不能 createb,不能 createuser;所有操作都返回错误信息

Fatal: role root does not exist
root is my account name, which I created while installing Postgresql

致命:角色 root 不存在
root 是我的帐户名,是我在安装时创建的Postgresql

But I am able to connect using:

但我可以使用以下方法进行连接:

 username : postgres  

How can I connect to postgres using role root?
There is a solution mentioned for linux platforms using su command herebut not able to figure out solution for windows7

如何使用 role 连接到 postgres root此处
提到了使用 su 命令针对 linux 平台的解决方案,但无法找出适用于 windows7 的解决方案

Thanks in Advance

提前致谢

回答by a_horse_with_no_name

If you want to login to Postgres using the username rootyou need to first create such a user.

如果您想使用用户名登录 Postgres,root您需要先创建一个这样的用户。

You first need to login as the Postgres super user. This is typically postgres(and is specified during installation):

您首先需要以 Postgres 超级用户身份登录。这通常是postgres(并在安装期间指定):

psql -U postgres ....

then you can create roles and databases:

然后你可以创建角色和数据库:

psql (9.4.0)
Type "help" for help.

postgres=# create user root with password 'verysecret';
CREATE ROLE
postgres=# \q

c:\
c:\>psql -U root postgres
psql (9.4.0)
Type "help" for help.

postgres=>

Logged in as the superuser you can also grant the rootuser the necessary privileges.

作为超级用户登录,您还可以授予root用户必要的权限。

All parameters for psqlare documented in the manual.

所有参数psql都记录在手册中

Creating users and databases is also documented in the manual:

手册中还记录了创建用户和数据库:

回答by Natacha

In some cases, when you install postgres the initial DB is not created.

在某些情况下,当您安装 postgres 时,不会创建初始数据库。

You need to execute initdb.

您需要执行 initdb