使用pg_dump只能使用compress参数进行备份损坏?

hrt*_*lik 5 postgresql backup restore pg-dump pg

我使用此命令备份200GB数据库(postgres 9.1,win7 x64):

pg_dump -Z 1 db_name > backup

它创建了16GB的文件,我觉得很好,因为以前的备份工作(并且由ext工具打包)具有相似的大小.现在,当我尝试使用时恢复到PG9.2时pg_restore,我收到错误:

input file does not appear to be a valid archive

pg_restore -Ft:

[tar archiver] corrupt tar header found in ? (expected 13500752, com
puted 78268) file position 512

Gzip也表明它已经损坏了.当我在Total Commander中打开备份文件时,内部文件只有1.8GB.当我在寻找解决方案时,-Cf可能需要使用参数进行转储.

现在哪种格式的文件?它只是tar或gzip(winrar显示gzip)?有没有办法正确地恢复它或者它以某种方式被破坏(转储时没有错误)?可能是由于tar或gzip的文件大小限制?

小智 6

你在"备份"中输出的只是压缩普通的sql.你可以通过提示检查它:

gzip -l backup
Run Code Online (Sandbox Code Playgroud)

不幸的是,pg_retore不提供恢复PLAIN SQL的可能性,所以你只需要解压缩文件并使用psql -f <FILE>命令:

zcat backup > backup.sql
psql -f backup.sql
Run Code Online (Sandbox Code Playgroud)

pg_dump -Fc根据"Frank Heikens"的建议,不可能使用postgres 9.1 进行转储,因为转储格式在主要版本之间不兼容,例如9.0 - > 9.1 - > 9.2,而"pg_restore"会在9.2上给出错误


Fra*_*ens 0

你的转储是普通的 SQL,它不是 tar 格式,就像你尝试在 pg_restore 中使用的那样。当您想要压缩格式时使用 --format=custom 或 -Fc 并在 pg_restore 中使用此设置。检查手册