postgresql - Heroku pg :pull to my local database 权限被拒绝

标签 postgresql heroku pull

我有一个在 Heroku 上运行数据库的实时应用程序,但数据库需要更新,因此我的计划是提取数据库,更新它,在我的开发服务器上测试它,然后将其推送到生产环境。第一步,我正在努力拉动 heroku 数据库来覆盖我的本地数据库。我正在使用以下命令:

PGUSER=userforlocaldb PGPASSWORD=passwordforlocaldb heroku pg:pull HEROKU_POSTGRESQL_herokudbcolor localdbname --app herokuappname

我收到此错误消息:

 !    createdb: database creation failed: ERROR:  permission denied to create database
 !    
 !    Unable to create new local database. Ensure your local Postgres is working and try again.

我还尝试使用我的heroku 数据库填充 PGUSER 和 PGPASSWORD 值,但这不起作用。

我在这里缺少什么?

编辑:我更改了 super 用户 postgres 的密码并重新运行该命令。我收到此错误:用户“postgres”的对等身份验证失败

最佳答案

我能够重现您的问题,但我也能够根据 Gabriel 的建议来纠正它,将 postgres 的访问方法从 peer 更改为 md5 。每当您更改 pg_hba.conf 时,您都必须记住重新启动 Postgres。在 Ubuntu 上,应该这样做:

sudo service postgresql restart

另一个解决方案:

或者,如果用户权限对您来说不是一个大问题(例如,您的系统上没有其他用户),例如在虚拟机中,您可以为自己授予 PostgreSQL super 用户权限:

sudo -u postgres createuser -s $YOUR_USERNAME [-P]

这将允许您创建一个新的数据库(localdbname)并加载plpgsql extension在这种情况下这似乎是必要的。 (由于 plpgsql,拥有 CREATEDB 角色似乎不够。)

现在您应该能够在没有 PGUSERPGPASSWORD 的情况下运行原始命令:

heroku pg:pull HEROKU_POSTGRESQL_herokudbcolor localdbname --app herokuappname

编辑答案:

如果在运行 heroku pg:pull 命令时仍然提示您输入密码,您需要为新的 Postgres 用户设置一个密码,该密码可能与您的操作系统登录名相同用户(echo\whoami``)。您可以通过在上面的 createuser 命令中包含 -P 标志来完成此操作,这将提示您输入新用户的密码,或者以 Postgres super 用户身份登录(例如,postgres)和 setting the password in psql .

附录/警告:

结合这两种解决方案可能不是一个好主意,因为如果 postgres 用户通过 进行身份验证,则运行 sudo -u postgres ... 时可能会出现问题code>md5 但未设置密码,这在 Linux 安装中通常是默认情况。就我个人而言,一旦创建了新用户/角色,我发现以 Postgres super 用户身份(whoami)发出命令比以 postgres super 用户身份更方便。

无论哪种方式,要运行 heroku pg:pull 命令,我认为您需要为用户设置密码并拥有 super 用户权限。

关于postgresql - Heroku pg :pull to my local database 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34667671/

相关文章:

git - 为什么在 Visual Studio Code 中执行 git pull 后我有未提交的更改?

security - 到 Amazon EC2 的 PostgreSQL SSH 隧道?

ruby-on-rails-3 - 在 heroku 上生产之前部署到测试服务器

ruby-on-rails - 如何将两个 Rails 应用程序数据库和模型链接在一起?

php - git pull 通过 PHP exec IIS

git - 克隆裸 git 存储库的单个路径

sql - 如何在 Postgresql 中对 JSONB 数组中的值求和?

Django 数据库创建或更新错误

postgresql - AgensGraph-Btree VS Neo4j-IndexFree

ruby-on-rails - 如何为 Puma 检查 Rails 应用程序的线程安全