Heroku pgbackups:localhost恢复时的语法错误

时间:2012-05-28 16:31:12

标签: ruby-on-rails-3 postgresql heroku

尝试使用heroku pgbackups -tool恢复数据库备份。

我通过公开网址下载备份:

$ heroku pgbackups:url 'backup-name'

创建数据库:

$ createdb 'dbname' -U postgres

并尝试从* .dump文件恢复:

$ psql -U postgres -d 'dbname' -f *.dump

我最终遇到了以下类型的语法错误:

ERROR:  syntax error at or near "PGDMP"
...
ERROR:  invalid byte sequence for encoding "UTF8": 0x9d
HINT:  This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding"

好的,所以这与编码有关 - 但是我如何解决呢?

config / application.rb和我的postgres服务器都将编码设置为UTF-8。 database.yml配置了sqlite(尚未涉及生产配置)。 Gemfile只是:

gem 'pg'

1 个答案:

答案 0 :(得分:53)

我找到了答案directly from the manual

$ curl -o latest.dump `heroku pgbackups:url`

$ pg_restore --verbose --clean --no-acl --no-owner -h myhost -U myuser -d mydb latest.dump