PostgreSQL - 从数据库转储中恢复一张表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38508704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:20:41  来源:igfitidea点击:

PostgreSQL - restoring one table from database dump

postgresql

提问by Dimon

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

回答by maniek

There is no easy way, except for some hacks (like using awk to cut the part of the file).

没有简单的方法,除了一些技巧(比如使用 awk 来剪切文件的一部分)。

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.

如果转储不是太大,最简单的方法是将完整备份还原到临时数据库 ( gzcat backup_file.gz | psql -h host -U user database_name) 转储一张表 ( pg_dump -t my_table),然后将其还原。

For the future the custom format (pg_dump -Fc > database.dump) is the way to go. The you can use pg_restoreto restore a single table : pg_restore -t my_table -d database_name database.dump.

对于未来,自定义格式 ( pg_dump -Fc > database.dump) 是要走的路。您可以使用pg_restore来恢复单个表:pg_restore -t my_table -d database_name database.dump