Postgresql初始配置:如何作为postgres用户访问?

时间:2013-03-26 15:51:23

标签: postgresql postgresql-9.2 ubuntu-12.10

安装postgresql后,我试了一下,输入createdb mydb,就像在文档中写的一样。然后发生以下错误:

createdb: could not connect to database postgres: FATAL:  role "xxx" does not exist

我研究了文档,其中说:

  

您需要成为安装PostgreSQL的操作系统用户(通常是postgres)才能创建第一个用户帐户

我试过访问psql(在我的情况下使用sudo -u postgres psql,使用Ubuntu 12.10)。 但那我该怎么办?

2 个答案:

答案 0 :(得分:1)

如果db由用户postgres拥有,则可以执行以下操作

createdb -U postgres dbname

因为默认情况下postgresql将信任来自localhost的连接。

答案 1 :(得分:0)

su - postgres

并在您登录后:

createdb mydb