我正在设置PostgreSQL 9.1。我不能用PostgreSQL做任何事情:不能createdb,不能createuser;所有操作都返回错误消息
Fatal: role h9uest does not exist
h9uest是我的帐户名,我在这个帐户下执行apt-get安装PostgreSQL 9.1。 根帐户仍然存在类似的错误。
我正在设置PostgreSQL 9.1。我不能用PostgreSQL做任何事情:不能createdb,不能createuser;所有操作都返回错误消息
Fatal: role h9uest does not exist
h9uest是我的帐户名,我在这个帐户下执行apt-get安装PostgreSQL 9.1。 根帐户仍然存在类似的错误。
当前回答
sudo -u postgres createuser --superuser $USER
sudo -u postgres createdb $USER
这绝对适合你。
其他回答
使用apt-get安装postgres不会创建用户角色或数据库。
创建超级用户角色和个人用户帐户数据库:
Sudo -u postgres createuser -s $(whoami);createdb whoami(美元)
对于Postgres 9.5版本,使用以下命令:
psql -h localhost -U postgres
希望这能有所帮助。
使用——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
在我的案例中,手动创建一个DB集群解决了这个问题。
由于某种原因,当我安装postgres时,没有创建“初始DB”。执行initdb对我来说很管用。
这个解决方案在PostgreSQL Wiki -第一步:
initdb 通常情况下,在操作系统中安装postgres会创建一个“初始DB”,并启动postgres服务器守护进程。如果没有,则需要运行initdb
这对我来说很管用:
psql -h localhost -U postgres