简体   繁体   English

pg_restore: [archiver] postgres 中的输入文件太短错误

[英]pg_restore: [archiver] input file is too short error in postgres

I am trying to dump the database in my local system by using the command:我正在尝试使用以下命令将数据库转储到我的本地系统中:

pg_restore --host=localhost --port=5432 --dbname=dev_db --no-owner --no-privileges db_dump_new.backup

but I am getting the error:但我收到错误:

pg_restore: [archiver] input file is too short (read 0, expected 5)

What am I doing wrong?我究竟做错了什么?

If you're using docker and redirecting the dump file from your local machine, don't forget -i .如果您使用 docker 并从本地计算机重定向转储文件,请不要忘记-i This won't work:这行不通:

docker exec <container> pg_restore -U "$USER" < ./localfile.dump;

Be sure that the docker container can see standard in with the -i option!确保 docker 容器可以使用-i选项查看标准! This should work:这应该有效:

docker exec -i <container> pg_restore -U "$USER" < ./localfile.dump;

I encountered the same error.我遇到了同样的错误。 In my case I had simply neglected to specify the backup file at the end of the command.就我而言,我只是忽略了在命令末尾指定备份文件。

In my case I used docker就我而言,我使用了 docker

$ docker exec a5f7b094c523 pg_restore -d my_new_db < "./2256.dump"
pg_restore: [archiver] input file is too short (read 0, expected 5)

And the issue was that "./2256.dump" is not a binary file but a plain sql text dump.问题是“./2256.dump”不是二进制文件,而是纯sql文本转储。

To check that just do检查只是做

$ head ~/2256.dump                                                                                                    
--
-- PostgreSQL database dump
--

-- Dumped from database version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)
-- Dumped by pg_dump version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;

And to import sql dump fo并导入 sql dump fo

$ pv ~/2256.dump |docker-compose -f docker-compose.dev.yml -f docker-compose.override.yml -T db psql "fight-round3" 

Use this command, it will work perfectly to restore the db file using sql file in Postgres 13 in pgadmin 4使用此命令,它将完美地使用 pgadmin 4 中的 Postgres 13 中的 sql 文件恢复 db 文件

C:\Program Files\PostgreSQL\13\bin>psql -U user_name db_name< D:\dbfile\sql_file.sql

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Postgres 教程:pg_restore:[archiver] 输入文件似乎不是有效的存档 - Postgres Tutorial: pg_restore: [archiver] input file does not appear to be a valid archive pg_restore: [目录归档程序] 无法打开输入文件。 尝试恢复数据库时出错 - pg_restore: [directory archiver] could not open input file. Error while trying to restore DB pg_restore错误:pg_restore:文件头中的[archiver]不支持的版本(1.13) - pg_restore error: pg_restore: [archiver] unsupported version (1.13) in file header pg_restore:[存档]输入文件在使用Pgadmin 4的PostgreSQL中似乎不是有效的存档错误 - pg_restore: [archiver] input file does not appear to be a valid archive error in PostgreSQL using Pgadmin 4 pg_restore:[archiver]输入文件在ubuntu 18.04中使用Pgadmin 4的PostgreSQL中似乎不是有效的存档错误 - pg_restore: [archiver] input file does not appear to be a valid archive error in PostgreSQL using Pgadmin 4 in ubuntu 18.04 pg_restore: [archiver] 文件头中不受支持的版本 (1.13) - pg_restore: [archiver] unsupported version (1.13) in file header pg_restore: [archiver] 文件头中不支持的版本 (1.14) - pg_restore: [archiver] unsupported version (1.14) in file header pg_restore:[存档(db)]处理目录时出错: - pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore:错误:输入文件似乎不是有效的存档 - pg_restore: error: input file does not appear to be a valid archive 运行 pg_restore 时在文件头中获取“[archiver] 不受支持的版本(1.13)” - Getting "[archiver] unsupported version (1.13) in file header" when running pg_restore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM