postgresql 从 sql 文件恢复单表转储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21404141/
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
restore single table dump from a sql file
提问by Shiva Krishna Bavandla
I have full dump of sql file like dump_full.sql
of size 1.3GB
我有像dump_full.sql
大小一样的sql 文件的完整转储1.3GB
And it has some tables like
它有一些表格,例如
dancing_core_spice
dancing_sea_beast
forde_clear_one
forde_super_now
Now what i want is need to restore/fetch/dump only data
of these tables from dump_full.sql
file
现在我想要的是only data
从dump_full.sql
文件中恢复/获取/转储这些表
psql -U postgres --table=dancing_core_spice dump_full.sql > dancing_core_spice.sql
i tried the above command but it is not working
我试过上面的命令,但它不起作用
So can anyone please let me know how to take the dump of only single table from the sql file(full dump)
所以任何人都可以请让我知道如何从 sql 文件中获取单个表的转储(完整转储)
回答by Francisco Puga
For these type of operations the dump file should be in the postgresql custom format created with pg_dump:
对于这些类型的操作,转储文件应该是使用pg_dump创建的 postgresql 自定义格式:
pg_dump -Fc
Then you can restore a single table with pg_restore
然后你可以用pg_restore恢复单个表
pg_restore --table=dancing_core_spice dump_full.sql > dancing_core_spice.sql
This questionprovides tips to handle your actual case:
这个问题提供了处理您的实际案例的技巧:
- Extract the sql code from the file. With an editor, a script or whatever
- Restore the dump to temp database and dump it again with pg_dump
- 从文件中提取sql代码。使用编辑器、脚本或其他任何东西
- 将转储恢复到临时数据库并使用 pg_dump 再次转储