postgresql psql 致命角色不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28213929/
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
psql fatal role does not exist
提问by whiplash
I recently installed the latest version of Ubuntu and I'm not used to it yet. I had several problems connecting PostgreSQL with pgadmin3.
我最近安装了最新版本的 Ubuntu,但我还不习惯。我在连接 PostgreSQL 和 pgadmin3 时遇到了几个问题。
I tried to follow several tutorials to create a localhost server which I can use in pgadmin3. I didn't really hit the mark and I think I made it worse by installing, uninstalling, installing, uninstalling, trying answers I found... At this point I'm not sure my PostgreSQL is clean. It could be possible that I have two PostgreSQL installed, once again, I'm not sure. I tried to uninstall it but I had an error which basically said PostgreSQL wasn't in sudo.
我尝试按照几个教程创建一个可以在 pgadmin3 中使用的本地主机服务器。我并没有真正达到目标,我认为我通过安装、卸载、安装、卸载、尝试我找到的答案使情况变得更糟......此时我不确定我的 PostgreSQL 是否干净。有可能我安装了两个 PostgreSQL,再次,我不确定。我试图卸载它,但我有一个错误,基本上说 PostgreSQL 不在 sudo 中。
The thing is I now have this error running psql in the console:
问题是我现在在控制台中运行 psql 时出现此错误:
$psql
psql: FATAL: role "user" does not exist
I can't find the pg_hba.conf
and at this point I'm too afraid to make things even worse by trying following any other posts.
我找不到pg_hba.conf
并且在这一点上我太害怕尝试关注任何其他帖子而使事情变得更糟。
How could I make this work?
我怎么能让这个工作?
回答by niko
As pointed out in the comments, your pg_hba.conf seems fine.
正如评论中指出的那样,您的 pg_hba.conf 看起来不错。
Usually, the database will run as the postgres user (check ps aux | grep postgres
to find out the username postgres is running under).
通常,数据库将以 postgres 用户身份运行(检查ps aux | grep postgres
以找出运行 postgres 的用户名)。
Log in as that user, for example sudo su - postgres
, then create a user matching your normal Ubuntu user account (createuser username
), and finally create a database with that same name and set the owner (-O
) to that database user, like this: createdb -O username username
).
例如sudo su - postgres
,以该用户身份登录,然后创建一个与您的普通 Ubuntu 用户帐户 ( createuser username
)匹配的用户,最后创建一个具有相同名称的数据库并将所有者 ( -O
) 设置为该数据库用户,如下所示: createdb -O username username
)。
That should make calling psql
work, and pgadmin - as long as you start it as your default user, username - should work as well.
这应该使呼叫psql
工作,并且 pgadmin - 只要您以默认用户、用户名启动它 - 也应该工作。
Edit: By default, psql
will use your Linux username as default value for both the database-username and the database-name. You can override the username by using -U someotherusername
, and connect to a different database by adding that DB name to the command line, such as psql someotherdbname
. You might also find psql -l
useful for listing the existing databases.
编辑:默认情况下,psql
将使用您的 Linux 用户名作为数据库用户名和数据库名的默认值。您可以使用 覆盖用户名-U someotherusername
,并通过将该数据库名称添加到命令行来连接到不同的数据库,例如psql someotherdbname
. 您可能还会发现psql -l
列出现有数据库很有用。
回答by watsy0007
sudo -u postgres createuser user
may help you to create a new user with all the privileges of postgres
可以帮助您创建一个具有 postgres 所有权限的新用户
回答by Amr Arafat
Use the postgres user:
使用 postgres 用户:
sudo su postgres
and then use psql.
然后使用 psql。
If you still face problems check this link: PostgreSQL error: Fatal: role "username" does not exist
如果您仍然遇到问题,请检查此链接:PostgreSQL 错误:致命:角色“用户名”不存在
回答by Giordhano
In windows 10 this works for fine
在 Windows 10 中,这很好用
pg_restore --format=c --verbose --no-owner --no-privileges --dbname=MYDB --username=postgres --no-password --jobs=8 F:/MYBK.backup
pg_restore --format=c --verbose --no-owner --no-privileges --dbname=MYDB --username=postgres --no-password --jobs=8 F:/MYBK.backup
--username=(role) and --no-password are necesaries
--username=(role) 和 --no-password 是必需的
回答by Maruf Alom
Though it's a bit question old if you're facing this on windows, simply delete Postgres data
directory and re-initialize Postgres data by running initdb /data
尽管如果您在 Windows 上遇到这个问题,这有点老问题,只需删除 Postgresdata
目录并通过运行重新初始化 Postgres 数据initdb /data