psql致命角色不存在 [英] psql fatal role does not exist
问题描述
我最近安装了最新版本的Ubuntu,但还不习惯。我在将PostgreSQL与pgadmin3连接时遇到了一些问题。
I recently installed the latest version of Ubuntu and I'm not used to it yet. I had several problems connecting PostgreSQL with pgadmin3.
我尝试遵循一些教程来创建可在pgadmin3中使用的本地主机服务器。我并没有真正达到目标,我认为我会通过安装,卸载,安装,卸载,尝试找到的答案来使情况变得更糟……目前,我不确定PostgreSQL是否干净。我不确定,可能我已经安装了两个PostgreSQL。我尝试卸载它,但出现了一个错误,该错误基本上表明PostgreSQL不在sudo中。
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.
问题是我现在在控制台中运行psql时遇到此错误:
The thing is I now have this error running psql in the console:
$psql
psql: FATAL: role "user" does not exist
我找不到 pg_hba.conf
并在在这一点上,我太害怕通过尝试遵循其他任何帖子来使事情变得更糟。
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看起来还不错。
As pointed out in the comments, your pg_hba.conf seems fine.
通常,数据库将以postgres用户身份运行(请检查 ps aux | grep postgres
来查找运行postgres的用户名)。
Usually, the database will run as the postgres user (check ps aux | grep postgres
to find out the username postgres is running under).
以该用户身份登录,例如 sudo su-postgres
,然后创建与常规Ubuntu用户帐户匹配的用户( createuser用户名
),并最终使用s创建数据库ame名称,并将所有者( -O
)设置为该数据库用户,例如: createdb -O用户名username
) 。
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
).
只要您以默认用户身份启动 psql
和pgadmin,它就可以正常工作,用户名-应该也可以。
That should make calling psql
work, and pgadmin - as long as you start it as your default user, username - should work as well.
编辑:默认情况下, psql
将使用您的Linux用户名作为默认值数据库用户名和数据库名。您可以使用 -U someotherusername
覆盖用户名,并通过在命令行中添加该数据库名称来连接到其他数据库,例如 psql someotherdbname。
。您可能还会发现 psql -l </ code>对于列出现有数据库很有用。
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致命角色不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!