postgresql 邮政。角色“root”不存在。尝试从 Heroku pg:pull 数据库时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25049504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:44:42  来源:igfitidea点击:

Postgres. role "root" does not exist. When trying to pg:pull database from Heroku

postgresqlheroku

提问by Alejandro Veintimilla

Im new to Postgres and to Heroku. I am trying to pull the database from Heroku but I'm missing something simple. I did:

我是 Postgres 和 Heroku 的新手。我正在尝试从 Heroku 中提取数据库,但我错过了一些简单的东西。我做了:

heroku pg:pull HEROKU_POSTGRESQL_IVORY_URL localdb

And I got the error:

我得到了错误:

createdb: database creation failed: ERROR:  permission denied to create database

Then I tried the same with "sudo". and I got:

然后我用“sudo”尝试了同样的方法。我得到了:

createdb: could not connect to database template1: FATAL:  role "root" does not exist

So, it must be I'm missing some simple commands I can't find. Im on Linux, I have Postgres installed and working.

所以,一定是我遗漏了一些我找不到的简单命令。我在 Linux 上,我安装了 Postgres 并且正在工作。

回答by a_horse_with_no_name

createdbis a wrapper around the SQL statement CREATE DATABASEand as such it needs to connect to the database.

createdb是 SQL 语句的包装器CREATE DATABASE,因此它需要连接到数据库。

By default all Postgres commandline tools try to connect to the database using the current operating system user. As the error message indicates there is not user named rootin the database. So you need to pass the name of the Postgres superuser in order for createdbto be able to connect. This user is usually named postgres.

默认情况下,所有 Postgres 命令行工具都尝试使用当前操作系统用户连接到数据库。由于错误消息表明root数据库中没有用户名。因此,您需要传递 Postgres 超级用户的名称createdb才能进行连接。此用户通常名为postgres

Another option is to switch the Linux user to to postgresif such a Linux user exists.

postgres如果存在这样的 Linux 用户,另一种选择是将 Linux 用户切换到。

I don't know Heroku and I don't know how you started createdb, but the parameter to pass a username is -U(for all Postgres command line programs). So you'd need

我不知道 Heroku 也不知道你是如何开始的createdb,但是传递用户名的参数是-U(对于所有 Postgres 命令行程序)。所以你需要

 createdb -U postgres name_of_new_database

回答by Ezrqn Kemboi

Try to use:

尝试使用:

sudo su - postgres

须藤 su - postgres

Then createdb using:

然后使用:

createdb name_of_db;

createdb name_of_db;