[英]Error when using pg_restore to restore database in docker compose
I ran the following commands to create the dump file我运行以下命令来创建转储文件
sudo docker-compose up -d db
sudo docker exec –i container_name pg_dump –username username database_name > desired_path/dump.sql
And then I added the file to an existing volume in the docker-compose.override.yml
file然后我将该文件添加到docker-compose.override.yml
文件中的现有卷中
version: '3.7'
services:
db:
container_name: seqdb-db-container
volumes:
- ./dump.sql:path_to_volume_used_by_container
ports:
- 5432:5432
Finally I run最后我跑
sudo docker exec –i container_name psql –username username database_name < path_to_dump_file
and I get the following error:我收到以下错误:
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
I want to use docker exec pg_restore
without installing psql
.我想使用docker exec pg_restore
而不安装psql
。 Is there a solution to this or did I mount my volume incorrectly?是否有解决方案或我是否错误地安装了我的卷?
From the pgdump docs :从pgdump 文档:
-F format -F 格式
--format=format --格式=格式
Selects the format of the output.选择输出的格式。 format can be one of the following:格式可以是以下之一:p磷
plain清楚的
Output a plain-text SQL script file (the default).输出纯文本 SQL 脚本文件(默认)。
So the default output format for pg_dump
is a plain-text SQL file (which it appears you expect because you call the output dump.sql
)所以pg_dump
的默认输出格式是一个纯文本的 SQL 文件(它看起来是你期望的,因为你调用了输出dump.sql
)
Now from the docs for pg_restore现在来自pg_restore的文档
pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats. pg_restore 是一个实用程序,用于从 pg_dump 创建的非纯文本格式之一的存档中恢复 PostgreSQL 数据库。
So the error, input file appears to be a text format dump. Please use psql
所以错误, input file appears to be a text format dump. Please use psql
input file appears to be a text format dump. Please use psql
, should be expected based on your actions. input file appears to be a text format dump. Please use psql
,应该根据您的操作进行预期。 pg_restore
does not support restoring plain-text dumps - to restore those you should use psql
(as per the error). pg_restore
不支持恢复纯文本转储 - 恢复那些你应该使用psql
(根据错误)。
The quick solution is to request a non-plain-text format when using pg_dump
(eg --format=custom
).快速解决方案是在使用pg_dump
时请求非纯文本格式(例如--format=custom
)。 However I am a little confused by your reluctance to use psql
?但是,我对您不愿意使用psql
感到有些困惑?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.