恢复 postgres 数据库备份时出错
我已经设置了一个系统来自动从我的 Heroku 部署的 Rails 应用程序下载并存储数据库转储。一切工作都很好,但是当我下载转储并将其恢复到我的本地 postgres 服务器,然后尝试在恢复的数据库上运行我的本地应用程序时,我收到此错误
ActiveRecord::StatementInvalid in HomeController#index
PGError: ERROR: permission denied for relation users : SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
任何人对这可能是什么有任何建议吗?我检查了我的 postgres 权限,所有表和数据库本身都属于 postgres 用户。我也尝试过GRANT ALL
但没有成功。
I've setup a system to automatically download and store a db dump from my Heroku deployed rails app. Everything is working great but when I download the dump and restore it to my local postgres server then try and run my local app off that restored database I get this error
ActiveRecord::StatementInvalid in HomeController#index
PGError: ERROR: permission denied for relation users : SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
Anyone have any suggestions on what that could be? I've checked my postgres permissions and all tables and the database itself belong to the postgres user. I've tried GRANT ALL
as well with no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览您的 pgdump.sql 文件并删除每个 CREATE TABLE 语句后面的行,这些语句类似于:
然后从中运行恢复,它应该可以工作。这些行将表的所有者更改为heroku应用程序自动生成的数据库用户名,这在本地没有意义,因此您可以删除它们。
我还建议 grep 查找该用户名的任何其他出现并删除它们。
Go through your
pgdump.sql
files and remove the lines after eachCREATE TABLE
statement that say something like:Then run your restore from that and it should work. Those lines change the owner of the tables to your heroku app's autogenerated db username, which is meaningless locally, so you can just remove them.
I'd also recommend greping for any other occurrences of that username and removing those too.
您使用的 PostgreSQL 用户很可能与该表的所有者不同。
我想您在该数据库和这个数据库上有不同的用户?
Most probably the PostgreSQL user you are using is different one that is owner of this table.
I suppose you have different user on that database and on this one?