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

Fatal: role h9uest does not exist

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


当前回答

工作方法,

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

其他回答

sudo su - postgres

psql template1

在PGSQL上创建具有“超级用户”权限的角色

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

然后创建用户

CREATE USER username; 
eg. CREATE USER demo;

为用户分配权限

GRANT ROOT TO username;

然后启用该用户登录,这样你就可以从普通的$ terminal运行:psql template1:

ALTER ROLE username WITH LOGIN;

我把它安装在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

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

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.

在我的案例中,手动创建一个DB集群解决了这个问题。

由于某种原因,当我安装postgres时,没有创建“初始DB”。执行initdb对我来说很管用。

这个解决方案在PostgreSQL Wiki -第一步:

initdb 通常情况下,在操作系统中安装postgres会创建一个“初始DB”,并启动postgres服务器守护进程。如果没有,则需要运行initdb

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