[英]Could not connect to database postgres: FATAL: role“_postgres” does not exist
[英]cannot connect to template1: FATAL: role “_postgres” does not exist
在OS X 10.10上工作,从此处安装了postgreSQL和PostGIS,psql和9.3.5。 我很难让postgreSQL运行。
我尝试遵循有关psql和PostGis的OSM教程。 但似乎相当困难......我被困在这里 。 他们建议像这样创建用户:
sudo -u postgres createuser christoph
那对我没有用。 我这样创建用户:
$ sudo -u _postgres createuser -U postgres christoph
这没有任何问题。 然后我尝试了这个:
$ sudo -u _postgres createdb --encoding=UTF8 --owner=christoph gis
> cannot connect to template1: FATAL: role "_postgres" does not exist
如果我刚刚创建_postgres
角色,怎么不存在?
我也不明白为什么
$ createdb mydb
> -bash: createdb: command not found
尽管我添加了如下路径,但它不起作用:
$ export PSQL_DIR=/usr/local/pgsql/bin/
$ export PATH="$PSQL_DIR:$PATH"
之前。
执行命令如下:
$ /usr/local/pgsql/bin/createdb mydb
> createdb: cannot create database: ERROR: permission denied to create database
我被安装psql的用户所迷...连接了吗?!
将系统用户 (存储在/etc/passwd
)与Postgres角色 (存储在数据库集群中)很容易混淆。
在第一个命令中,提到了两种类型的用户:
sudo -u _postgres
意思是“使用系统用户_postgres
执行以下命令” -U postgres
表示“以角色postgres
连接到Postgres集群” 但是,在下一个命令中:
sudo -u _postgres createdb --encoding=UTF8 --owner=christoph gis
您指定了相同的sudo -u _postgres
,但是缺少实际的Postgres命令的-U
参数(您说您希望christoph拥有新的数据库,但您没有说“我是christoph”)。
Postgres命令行工具的默认行为是猜测Postgres角色名称与系统用户名相同。 由于系统用户名为_postgres
(带下划线),而Postgres角色名为postgres
(无下划线),因此该假设失败,您将无法连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.