Mur*_*dam 7 postgresql pg-dump heroku pg-restore heroku-postgres
我在恢复表的架构时遇到一些困难。我转储了 Heroku Postgres 数据库,并使用 pg_restore 将其中一张表恢复到我的本地数据库(它有 20 多个表)。它已成功恢复,但当我尝试将新数据插入表中时遇到问题。
当我使用psql打开数据库时,我发现恢复的表包含所有数据,但其架构有零行。无论如何,我可以从转储中导入表及其架构吗?非常感谢。
这就是我将表恢复到本地数据库的方法:
pg_restore -U postgres --dbname my_db --table=message latest.dump
Run Code Online (Sandbox Code Playgroud)
编辑:
我按照官方文档尝试了类似的操作,但它被阻止了,什么也没有发生。我的数据库很小,不超过几兆字节,并且我尝试恢复的表架构不超过 100 行。
pg_restore -U postgres --dbname mydb --table=message --schema=message_id_seq latest.dump
Run Code Online (Sandbox Code Playgroud)
Har*_*_OK 15
作为更一般的答案(我需要从巨大的备份中恢复单个表),您可能想看看这篇文章:https ://thequantitative.medium.com/restoring-individual-tables-from-postgresql- pg-dump-using-pg-restore-options-ef3ce2b41ab6
# run the schema-only restore as root
pg_restore -U postgres --schema-only -d new_db /directory/path/db-dump-name.dump
# Restore per table data using something like
pg_restore -U postgres --data-only -d target-db-name -t table_name /directory/path/dump-name.dump
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27835 次 |
| 最近记录: |