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

Fatal: role h9uest does not exist

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


当前回答

使用——no-owner——no-privileges标记转储和恢复

e.g.

Dump - pg_dump——no-owner——no-privileges——format=c——dbname=postgres://userpass:username@postgres:5432/schemaname > /tmp/full.dump

恢复- pg_restore——no-owner——no-privileges——format=c——dbname=postgres://userpass:username@postgres:5432/schemaname /tmp/full.dump

其他回答

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

使用apt-get安装postgres不会创建用户角色或数据库。

创建超级用户角色和个人用户帐户数据库:

Sudo -u postgres createuser -s $(whoami);createdb whoami(美元)

对于Postgres 9.5版本,使用以下命令:

psql -h localhost -U postgres

希望这能有所帮助。

Windows用户:psql -U postgres

然后你应该看到PostgreSQL的命令行界面: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;