PostgreSQL - 从数据库转储中恢复一张表 [英] PostgreSQL - restoring one table from database dump
问题描述
如何从数据库转储中恢复一张表?我使用下一个命令进行转储:
How can I restore one table from database dump ? I make dump using the next command:
pg_dump -U admin -h localhost my-db-name | gzip - > /home/a2_db_backup/my-db-name-backup.sql.gz
推荐答案
没有简单的方法,除了一些 hacks(比如使用 awk 剪切文件的一部分).
There is no easy way, except for some hacks (like using awk to cut the part of the file).
如果转储不是太大,最简单的方法是将完整备份恢复到临时数据库(gzcat backup_file.gz | psql -h host -U user database_name
)转储一个表 (pg_dump -t my_table
),然后恢复它.
If the dump is not too big, the easiest thing to do is restore the full backup to a temporary database (gzcat backup_file.gz | psql -h host -U user database_name
) dump the one table (pg_dump -t my_table
), then restore it.
对于未来的自定义格式(pg_dump -Fc > database.dump
)是要走的路.您可以使用 pg_restore 来恢复单个表:pg_restore -t my_table -d database_name database.dump
.
For the future the custom format (pg_dump -Fc > database.dump
) is the way to go. The you can use pg_restore to restore a single table : pg_restore -t my_table -d database_name database.dump
.
这篇关于PostgreSQL - 从数据库转储中恢复一张表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!