我正在设置PostgreSQL 9.1。我不能用PostgreSQL做任何事情:不能createdb,不能createuser;所有操作都返回错误消息

Fatal: role h9uest does not exist

h9uest是我的帐户名,我在这个帐户下执行apt-get安装PostgreSQL 9.1。 根帐户仍然存在类似的错误。


当前回答

遵循以下步骤,它将为你工作:

run msfconsole type db_console some information will be shown to you chose the information who tell you to make: db_connect user:pass@host:port.../database sorry I don't remember it but it's like this one then replace the user and the password and the host and the database with the information included in the database.yml in the emplacement: /usr/share/metasploit-framework/config you will see. rebuilding the model cache in the background. Type apt-get update && apt-get upgrade after the update restart the terminal and lunch msfconsole and it works you can check that by typing in msfconsole: msf>db_status you will see that it's connected.

其他回答

工作方法,

vi /etc/postgresql/9.3/main/pg_hba.conf 本地所有postgres peer 这里将peer改为trust 重启,sudo服务postgresql重启 现在试试,psql -U postgres

sudo -u postgres createuser --superuser $USER

sudo -u postgres createdb $USER

这绝对适合你。

使用操作系统用户postgres来创建你的数据库——只要你还没有建立一个数据库角色,该角色具有与你的操作系统用户同名(在你的例子中是h9uest)对应的必要权限:

sudo -u postgres -i

按照这里或这里的建议。

然后再试一次。当以系统用户postgres的身份操作时,输入exit。

或者使用sudo以postgres的形式执行createuser命令,就像drees在另一个答案中演示的那样。

关键是使用与同名数据库角色匹配的操作系统用户通过身份验证授予访问权限。Postgres是初始化数据库集群的默认操作系统用户。手册:

为了引导数据库系统,需要重新初始化 系统中总是包含一个预定义角色。这个角色总是一个 默认情况下(除非在运行initdb时更改) 将与初始化的操作系统用户具有相同的名称 数据库集群。通常,这个角色将被命名为postgres。 为了创建更多的角色,你首先必须像这样连接 最初的作用。

我听说过使用非标准用户名或操作系统用户不存在的奇怪设置。你需要调整你的策略。

阅读手册中的数据库角色和客户端身份验证。

对于使用docker并正确遵循官方文档说明的用户,如果仍然遇到此问题,请重新启动窗口并重试。

我把它安装在macOS上,必须:

cd /Applications/Postgres.app/Contents/Versions/9.5/bin
createuser -U postgres -s YOURUSERNAME
createdb YOURUSERNAME

来源如下:https://github.com/PostgresApp/PostgresApp/issues/313#issuecomment-192461641