5

我使用 pgadmin 连接到 heroku postgres 数据库并创建了一个包含两个简单列的简单表:

id - bigint identity 
name - text

和简单的两行:

id   name
1    name1
2    name2

当我执行命令时

heroku pg:pull DATABASE_URL mylocaldb1234 --app nameless-dusk-05113

我得到错误:

pg_restore: error: unrecognized data block type (0) while searching archive
 !    pg_restore errored with 1

我检查了 postgres 本地和远程版本,它们是相同的。本地版本:

psql --version
psql (PostgreSQL) 12.5

pg_restore --version
pg_restore (PostgreSQL) 12.5

远程版本:

heroku pg:info
=== DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           5/20
PG Version:            12.5
Created:               2021-01-07 07:29 UTC
Data Size:             8.2 MB
Tables:                1
Rows:                  2/10000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-spherical-97042

远程 pg_restore 版本:

heroku run pg_restore --version
Running pg_restore --version on ⬢ nameless-dusk-05113... up, run.7775 (Free)
pg_restore (PostgreSQL) 12.5 (Ubuntu 12.5-1.pgdg18.04+1)
4

1 回答 1

0

heroku pg:pull应该自动化这里描述的稍微手动的过程:https ://devcenter.heroku.com/articles/heroku-postgres-import-export 。

虽然我遇到了同样的错误heroku pg:pull,但更多的手动过程有效。具体来说,

$ heroku pg:backups:capture
$ heroku pg:backups:download  # this creates a file latest.dump in your current directory
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d mydatabasename latest.dump

如果mydatabasename不存在,则必须在运行之前创建它pg_restore

$ createdb -U postgres mydatabasename
于 2021-10-09T09:05:23.210 回答