Docker Community Forums

Share and learn in the Docker community.

Using pg_dump with Docker exec

PostGres image: crunchy postgres: centos7-11.1-2.2.0

I am new to docker containers, but am running a PostGres instance in one - it is around 800GB in size.
I can run a backup using:
docker exec containerid pg_dump -Fc DBNAME > pg_backup.fc

or by going into the container:
docker exec -it containerid /bin/sh
and then running
pg_dump -Fc DBNAME > pg_backup.fc

The two output files would be in two different places - the first in the host machine, the second in the container volume.
My question(s) is this - going into the container tells pg_dump to send its output directly to the file
whereas the first command sends its output to stdout, then gets redirected to the host machines file system
Is there an “overhead” to doing this?
Is my container going to run more slowly while it tries to send 800GB to stdout, rather than having it go straight to the file in the volume?

Use the following command from a UNIX terminal:

docker exec <container_name> pg_dump <schema_name> > backup
The following command will dump only inserts from all tables:

docker exec <container_name> pg_dump --column-inserts --data-only <schema_name> > inserts.sql

Thank you, but do you know if using the above command is slower than entering the container in interactive mode and running pg_dump inside the container?