Postgres数据库没有任何角色

时间:2015-03-29 23:39:01

标签: macos postgresql

我最近在osx 10.10上安装了postgres版本9.3.5,我无法使用psql连接到它。我以自己的用户身份启动了服务器,如下所示:

jestep$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

使用pg_ctl status我确认服务器正在运行。但是无论我尝试使用什么用户名,我都无法连接到服务器。

jestep$ psql
psql: FATAL:  role "jestep" does not exist
jestep$ psql -U postgres
psql: FATAL:  role "postgres" does not exist
jestep$ psql -U _postgres
psql: FATAL:  role "_postgres" does not exist
jestep$ psql -U admin
psql: FATAL:  role "admin" does not exist
jestep$ psql -U root
psql: FATAL:  role "root" does not exist

以下是我的pg_hba.conf文件的内容:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

我已登记/etc/passwd,但没有名为postgres的用户,但有_postgres

在Ubuntu上发生过一次这种情况,我实际上不得不卸载postgres和所有扩展,重新安装它们,并初始化一个全新的数据库。我可以采取任何不那么激烈的方法吗?

1 个答案:

答案 0 :(得分:1)

通过在新目录中运行新的initdb来解决@ CraigRinger的建议。


注意:删除您的数据目录并运行新的initdb会破坏所有现有数据,因此如果您关注的PostgreSQL安装中有任何内容,则不应该执行此操作。

相关问题